forked from doctrine/dbal
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request doctrine#6191 from morozov/query-builder-row-lock-…
…options Enable skipping locked rows in QueryBuilder
- Loading branch information
Showing
25 changed files
with
715 additions
and
91 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
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
86 changes: 86 additions & 0 deletions
86
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,86 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\DBAL\Platforms\SQLServer\SQL\Builder; | ||
|
||
use Doctrine\DBAL\Platforms\SQLServerPlatform; | ||
use Doctrine\DBAL\Query\ForUpdate\ConflictResolutionMode; | ||
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; | ||
|
||
/** @internal The SQL builder should be instantiated only by database platforms. */ | ||
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->getConflictResolutionMode() === ConflictResolutionMode::SKIP_LOCKED) { | ||
$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; | ||
} | ||
} |
Oops, something went wrong.