-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable skipping locked rows in QueryBuilder
Co-authored-by: Herberto Graca <herberto.graca@lendable.co.uk>
- Loading branch information
Showing
21 changed files
with
568 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace Doctrine\DBAL\Platforms; | ||
|
||
use Doctrine\DBAL\SQL\Builder\SelectSQLBuilder; | ||
|
||
/** | ||
* Provides the behavior, features and SQL dialect of the MariaDB 10.6 (10.6.0 GA) database platform. | ||
*/ | ||
class MariaDb1060Platform extends MariaDb1052Platform | ||
{ | ||
public function createSelectSQLBuilder(): SelectSQLBuilder | ||
{ | ||
return AbstractPlatform::createSelectSQLBuilder(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
src/Platforms/SQLServer/SQL/Builder/SQLServerSelectSQLBuilder.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\DBAL\Platforms\SQLServer\SQL\Builder; | ||
|
||
use Doctrine\DBAL\Platforms\SQLServerPlatform; | ||
use Doctrine\DBAL\Query\SelectQuery; | ||
use Doctrine\DBAL\SQL\Builder\SelectSQLBuilder; | ||
|
||
use function count; | ||
use function implode; | ||
|
||
final class SQLServerSelectSQLBuilder implements SelectSQLBuilder | ||
{ | ||
private SQLServerPlatform $platform; | ||
|
||
public function __construct(SQLServerPlatform $platform) | ||
{ | ||
$this->platform = $platform; | ||
} | ||
|
||
public function buildSQL(SelectQuery $query): string | ||
{ | ||
$parts = ['SELECT']; | ||
|
||
if ($query->isDistinct()) { | ||
$parts[] = 'DISTINCT'; | ||
} | ||
|
||
$parts[] = implode(', ', $query->getColumns()); | ||
|
||
$from = $query->getFrom(); | ||
|
||
if (count($from) > 0) { | ||
$parts[] = 'FROM ' . implode(', ', $from); | ||
} | ||
|
||
$forUpdate = $query->getForUpdate(); | ||
|
||
if ($forUpdate !== null) { | ||
$with = ['UPDLOCK', 'ROWLOCK']; | ||
|
||
if ($forUpdate->shouldSkipLocked()) { | ||
$with[] = 'READPAST'; | ||
} | ||
|
||
$parts[] = 'WITH (' . implode(', ', $with) . ')'; | ||
} | ||
|
||
$where = $query->getWhere(); | ||
|
||
if ($where !== null) { | ||
$parts[] = 'WHERE ' . $where; | ||
} | ||
|
||
$groupBy = $query->getGroupBy(); | ||
|
||
if (count($groupBy) > 0) { | ||
$parts[] = 'GROUP BY ' . implode(', ', $groupBy); | ||
} | ||
|
||
$having = $query->getHaving(); | ||
|
||
if ($having !== null) { | ||
$parts[] = 'HAVING ' . $having; | ||
} | ||
|
||
$orderBy = $query->getOrderBy(); | ||
|
||
if (count($orderBy) > 0) { | ||
$parts[] = 'ORDER BY ' . implode(', ', $orderBy); | ||
} | ||
|
||
$sql = implode(' ', $parts); | ||
$limit = $query->getLimit(); | ||
|
||
if ($limit->isDefined()) { | ||
$sql = $this->platform->modifyLimitQuery($sql, $limit->getMaxResults(), $limit->getFirstResult()); | ||
} | ||
|
||
return $sql; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\DBAL\Query; | ||
|
||
/** @internal */ | ||
final class ForUpdate | ||
{ | ||
private bool $shouldSkipLocked; | ||
|
||
public function __construct(bool $shouldSkipLocked) | ||
{ | ||
$this->shouldSkipLocked = $shouldSkipLocked; | ||
} | ||
|
||
public function shouldSkipLocked(): bool | ||
{ | ||
return $this->shouldSkipLocked; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace Doctrine\DBAL\Query; | ||
|
||
final class Limit | ||
{ | ||
private ?int $maxResults; | ||
private int $firstResult; | ||
|
||
public function __construct(?int $maxResults, int $firstResult) | ||
{ | ||
$this->maxResults = $maxResults; | ||
$this->firstResult = $firstResult; | ||
} | ||
|
||
public function isDefined(): bool | ||
{ | ||
return $this->maxResults !== null || $this->firstResult !== 0; | ||
} | ||
|
||
public function getMaxResults(): ?int | ||
{ | ||
return $this->maxResults; | ||
} | ||
|
||
public function getFirstResult(): int | ||
{ | ||
return $this->firstResult; | ||
} | ||
} |
Oops, something went wrong.