[Messenger] Fix mssql compatibility for doctrine transport.
Add logic for locking row for update when the doctrine dbal connection is sqlsrv. This is a quick and dirty solution, but it prevents the need to rewrite the logic due to doctrine dbal limitations. See issue https://github.com/symfony/symfony/issues/39117
This commit is contained in:
parent
3e9f770e25
commit
37be094992
@ -16,6 +16,7 @@ use Doctrine\DBAL\DBALException;
|
|||||||
use Doctrine\DBAL\Driver\Result as DriverResult;
|
use Doctrine\DBAL\Driver\Result as DriverResult;
|
||||||
use Doctrine\DBAL\Exception;
|
use Doctrine\DBAL\Exception;
|
||||||
use Doctrine\DBAL\Exception\TableNotFoundException;
|
use Doctrine\DBAL\Exception\TableNotFoundException;
|
||||||
|
use Doctrine\DBAL\LockMode;
|
||||||
use Doctrine\DBAL\Query\QueryBuilder;
|
use Doctrine\DBAL\Query\QueryBuilder;
|
||||||
use Doctrine\DBAL\Result;
|
use Doctrine\DBAL\Result;
|
||||||
use Doctrine\DBAL\Schema\Comparator;
|
use Doctrine\DBAL\Schema\Comparator;
|
||||||
@ -161,9 +162,23 @@ class Connection
|
|||||||
->orderBy('available_at', 'ASC')
|
->orderBy('available_at', 'ASC')
|
||||||
->setMaxResults(1);
|
->setMaxResults(1);
|
||||||
|
|
||||||
|
// Append pessimistic write lock to FROM clause if db platform supports it
|
||||||
|
$sql = $query->getSQL();
|
||||||
|
if (($fromPart = $query->getQueryPart('from')) &&
|
||||||
|
($table = $fromPart[0]['table'] ?? null) &&
|
||||||
|
($alias = $fromPart[0]['alias'] ?? null)
|
||||||
|
) {
|
||||||
|
$fromClause = sprintf('%s %s', $table, $alias);
|
||||||
|
$sql = str_replace(
|
||||||
|
sprintf('FROM %s WHERE', $fromClause),
|
||||||
|
sprintf('FROM %s WHERE', $this->driverConnection->getDatabasePlatform()->appendLockHint($fromClause, LockMode::PESSIMISTIC_WRITE)),
|
||||||
|
$sql
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// use SELECT ... FOR UPDATE to lock table
|
// use SELECT ... FOR UPDATE to lock table
|
||||||
$stmt = $this->executeQuery(
|
$stmt = $this->executeQuery(
|
||||||
$query->getSQL().' '.$this->driverConnection->getDatabasePlatform()->getWriteLockSQL(),
|
$sql.' '.$this->driverConnection->getDatabasePlatform()->getWriteLockSQL(),
|
||||||
$query->getParameters(),
|
$query->getParameters(),
|
||||||
$query->getParameterTypes()
|
$query->getParameterTypes()
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user