8000 Merge branch '4.4' into 5.1 · grasmash/symfony@9ff1436 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9ff1436

Browse files
committed
Merge branch '4.4' into 5.1
* 4.4: [Messenger] Fix mssql compatibility for doctrine transport.
2 parents 8d512d9 + 42061de commit 9ff1436

File tree

1 file changed

+16
-1
lines changed
  • src/Symfony/Component/Messenger/Bridge/Doctrine/Transport

1 file changed

+16
-1
lines changed

src/Symfony/Component/Messenger/Bridge/Doctrine/Transport/Connection.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Doctrine\DBAL\Driver\Result as DriverResult;
1717
use Doctrine\DBAL\Exception;
1818
use Doctrine\DBAL\Exception\TableNotFoundException;
19+
use Doctrine\DBAL\LockMode;
1920
use Doctrine\DBAL\Query\QueryBuilder;
2021
use Doctrine\DBAL\Result;
2122
use Doctrine\DBAL\Schema\Comparator;
@@ -172,9 +173,23 @@ public function get(): ?array
172173
->orderBy('available_at', 'ASC')
173174
->setMaxResults(1);
174175

176+
// Append pessimistic write lock to FROM clause if db platform supports it
177+
$sql = $query->getSQL();
178+
if (($fromPart = $query->getQueryPart('from')) &&
179+
($table = $fromPart[0]['table'] ?? null) &&
180+
($alias = $fromPart[0]['alias'] ?? null)
181+
) {
182+
$fromClause = sprintf('%s %s', $table, $alias);
183+
$sql = str_replace(
184+
sprintf('FROM %s WHERE', $fromClause),
185+
sprintf('FROM %s WHERE', $this->driverConnection->getDatabasePlatform()->appendLockHint($fromClause, LockMode::PESSIMISTIC_WRITE)),
186+
$sql
187+
);
188+
}
189+
175190
// use SELECT ... FOR UPDATE to lock table
176191
$stmt = $this->executeQuery(
177-
$query->getSQL().' '.$this->driverConnection->getDatabasePlatform()->getWriteLockSQL(),
192+
$sql.' '.$this->driverConnection->getDatabasePlatform()->getWriteLockSQL(),
178193
$query->getParameters(),
179194
$query->getParameterTypes()
180195
);

0 commit comments

Comments
 (0)
0