Search
 
SCRIPT & CODE EXAMPLE
 

PHP

laravel postgres deadlock

namespace AppHelpersMySQL;

use Closure;
use Exception;
use IlluminateDatabaseMySqlConnection;
use IlluminateDatabaseQueryException;
use Log;
use PDOException;

/**
 * Class DeadlockReadyMySqlConnection
 *
 * @package AppHelpers
 */
class DeadlockReadyMySqlConnection extends MySqlConnection
{
    /**
     * Error code of deadlock exception
     */
    const DEADLOCK_ERROR_CODE = 40001;

    /**
     * Number of attempts to retry
     */
    const ATTEMPTS_COUNT = 3;

    /**
     * Run a SQL statement.
     *
     * @param  string    $query
     * @param  array     $bindings
     * @param  Closure  $callback
     * @return mixed
     *
     * @throws IlluminateDatabaseQueryException
     */
    protected function runQueryCallback($query, $bindings, Closure $callback)
    {
        $attempts_count = self::ATTEMPTS_COUNT;

        for ($attempt = 1; $attempt <= $attempts_count; $attempt++) {
            try {
                return $callback($this, $query, $bindings);
            } catch (Exception $e) {
                if (((int)$e->getCode() !== self::DEADLOCK_ERROR_CODE) || ($attempt >= $attempts_count)) {
                    throw new QueryException(
                        $query, $this->prepareBindings($bindings), $e
                    );
                } else {
                    $sql = str_replace_array('?', $this->prepareBindings($bindings), $query);
                    Log::warning("Transaction has been restarted. Attempt {$attempt}/{$attempts_count}. SQL: {$sql}");
                }
            }
        }

    }
}
Comment

laravel postgres deadlock

namespace AppHelpersMySQL;

use Config;
use IlluminateDatabaseConnectorsConnectionFactory;
use IlluminateDatabaseMySqlConnection;
use IlluminateDatabasePostgresConnection;
use IlluminateDatabaseSQLiteConnection;
use IlluminateDatabaseSqlServerConnection;
use InvalidArgumentException;
use PDO;

/**
 * Class YourAppConnectionFactory
 *
 * @package AppHelpersMySQL
 */
class YourAppConnectionFactory extends ConnectionFactory
{
    /**
     * Create a new connection instance.
     *
     * @param  string   $driver
     * @param  PDO     $connection
     * @param  string   $database
     * @param  string   $prefix
     * @param  array    $config
     * @return IlluminateDatabaseConnection
     *
     * @throws InvalidArgumentException
     */
    protected function createConnection($driver, PDO $connection, $database, $prefix = '', array $config = [])
    {
        if ($this->container->bound($key = "db.connection.{$driver}")) {
            return $this->container->make($key, [$connection, $database, $prefix, $config]);
        }

        switch ($driver) {
            case 'mysql':
                if ($config['database'] === Config::get('database.connections.mysql.database')) {
                    return new DeadlockReadyMySqlConnection($connection, $database, $prefix, $config);
                } else {
                    return new MySqlConnection($connection, $database, $prefix, $config);
                }
            case 'pgsql':
                return new PostgresConnection($connection, $database, $prefix, $config);
            case 'sqlite':
                return new SQLiteConnection($connection, $database, $prefix, $config);
            case 'sqlsrv':
                return new SqlServerConnection($connection, $database, $prefix, $config);
        }

        throw new InvalidArgumentException("Unsupported driver [$driver]");
    }
}
Comment

laravel postgres deadlock

public function register()
{
    $this->app->singleton('db.factory', function ($app) {
        return new YourAppConnectionFactory($app);
    });
}
Comment

PREVIOUS NEXT
Code Example
Php :: woocommerce status change date 
Php :: php file request 
Php :: https://stackoverflow.com/questions/34545641/php-artisan-makeauth-command-is-not-defined 
Php :: Éviter le spam de commentaires 
Php :: fpdf tutorial php mysql 
Php :: RouteSubscriber disallow user routes 
Php :: mysqli_query() expects parameter 1 to be mysqli 
Php :: pass variable in laravel ancher tag laravel 8 
Php :: WP Hero Img 
Php :: Crear un componente livewire 
Php :: form validation in php 
Php :: wpdb insert or if exists update 
Php :: Declaration of AppExportsTarefasExport::headings() must be compatible with MaatwebsiteExcelConcernsWithHeadings::headings(): array 
Php :: import facade laravel 
Php :: Round A Number 
Php :: exists:categories,id except a value laravel 
Php :: phpcs unabl 
Php :: cout post on category in controller laravel 
Php :: how to get name through id from mysql using php 
Php :: Yii2 hasMany relation additional condition 
Php :: PHP quoted_printable_decode — Convert a quoted-printable string to an 8 bit string 
Php :: hou to fill value in input box using php 
Php :: use the content to store in variable in wp 
Php :: auto complete order paid 
Php :: $request laravel undefined inside function query 
Php :: option to have array in function parameter 
Php :: function placing bet in guide using php 
Php :: php Change the WooCommerce loop product link based on a custom field 
Php :: propel find index 
Php :: php doctrine findby greater than 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =