diff options
author | polo <ordipolo@gmx.fr> | 2024-08-13 23:45:21 +0200 |
---|---|---|
committer | polo <ordipolo@gmx.fr> | 2024-08-13 23:45:21 +0200 |
commit | bf6655a534a6775d30cafa67bd801276bda1d98d (patch) | |
tree | c6381e3f6c81c33eab72508f410b165ba05f7e9c /vendor/doctrine/dbal/src/Platforms/SQLServer/SQL | |
parent | 94d67a4b51f8e62e7d518cce26a526ae1ec48278 (diff) | |
download | AppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.zip |
VERSION 0.2 doctrine ORM et entités
Diffstat (limited to 'vendor/doctrine/dbal/src/Platforms/SQLServer/SQL')
-rw-r--r-- | vendor/doctrine/dbal/src/Platforms/SQLServer/SQL/Builder/SQLServerSelectSQLBuilder.php | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/vendor/doctrine/dbal/src/Platforms/SQLServer/SQL/Builder/SQLServerSelectSQLBuilder.php b/vendor/doctrine/dbal/src/Platforms/SQLServer/SQL/Builder/SQLServerSelectSQLBuilder.php new file mode 100644 index 0000000..ea6bb60 --- /dev/null +++ b/vendor/doctrine/dbal/src/Platforms/SQLServer/SQL/Builder/SQLServerSelectSQLBuilder.php | |||
@@ -0,0 +1,84 @@ | |||
1 | <?php | ||
2 | |||
3 | declare(strict_types=1); | ||
4 | |||
5 | namespace Doctrine\DBAL\Platforms\SQLServer\SQL\Builder; | ||
6 | |||
7 | use Doctrine\DBAL\Platforms\SQLServerPlatform; | ||
8 | use Doctrine\DBAL\Query\ForUpdate\ConflictResolutionMode; | ||
9 | use Doctrine\DBAL\Query\SelectQuery; | ||
10 | use Doctrine\DBAL\SQL\Builder\SelectSQLBuilder; | ||
11 | |||
12 | use function count; | ||
13 | use function implode; | ||
14 | |||
15 | final class SQLServerSelectSQLBuilder implements SelectSQLBuilder | ||
16 | { | ||
17 | /** @internal The SQL builder should be instantiated only by database platforms. */ | ||
18 | public function __construct( | ||
19 | private readonly SQLServerPlatform $platform, | ||
20 | ) { | ||
21 | } | ||
22 | |||
23 | public function buildSQL(SelectQuery $query): string | ||
24 | { | ||
25 | $parts = ['SELECT']; | ||
26 | |||
27 | if ($query->isDistinct()) { | ||
28 | $parts[] = 'DISTINCT'; | ||
29 | } | ||
30 | |||
31 | $parts[] = implode(', ', $query->getColumns()); | ||
32 | |||
33 | $from = $query->getFrom(); | ||
34 | |||
35 | if (count($from) > 0) { | ||
36 | $parts[] = 'FROM ' . implode(', ', $from); | ||
37 | } | ||
38 | |||
39 | $forUpdate = $query->getForUpdate(); | ||
40 | |||
41 | if ($forUpdate !== null) { | ||
42 | $with = ['UPDLOCK', 'ROWLOCK']; | ||
43 | |||
44 | if ($forUpdate->getConflictResolutionMode() === ConflictResolutionMode::SKIP_LOCKED) { | ||
45 | $with[] = 'READPAST'; | ||
46 | } | ||
47 | |||
48 | $parts[] = 'WITH (' . implode(', ', $with) . ')'; | ||
49 | } | ||
50 | |||
51 | $where = $query->getWhere(); | ||
52 | |||
53 | if ($where !== null) { | ||
54 | $parts[] = 'WHERE ' . $where; | ||
55 | } | ||
56 | |||
57 | $groupBy = $query->getGroupBy(); | ||
58 | |||
59 | if (count($groupBy) > 0) { | ||
60 | $parts[] = 'GROUP BY ' . implode(', ', $groupBy); | ||
61 | } | ||
62 | |||
63 | $having = $query->getHaving(); | ||
64 | |||
65 | if ($having !== null) { | ||
66 | $parts[] = 'HAVING ' . $having; | ||
67 | } | ||
68 | |||
69 | $orderBy = $query->getOrderBy(); | ||
70 | |||
71 | if (count($orderBy) > 0) { | ||
72 | $parts[] = 'ORDER BY ' . implode(', ', $orderBy); | ||
73 | } | ||
74 | |||
75 | $sql = implode(' ', $parts); | ||
76 | $limit = $query->getLimit(); | ||
77 | |||
78 | if ($limit->isDefined()) { | ||
79 | $sql = $this->platform->modifyLimitQuery($sql, $limit->getMaxResults(), $limit->getFirstResult()); | ||
80 | } | ||
81 | |||
82 | return $sql; | ||
83 | } | ||
84 | } | ||