summaryrefslogtreecommitdiff
path: root/vendor/doctrine/dbal/src/Platforms/SQLServer
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/doctrine/dbal/src/Platforms/SQLServer')
-rw-r--r--vendor/doctrine/dbal/src/Platforms/SQLServer/Comparator.php50
-rw-r--r--vendor/doctrine/dbal/src/Platforms/SQLServer/SQL/Builder/SQLServerSelectSQLBuilder.php84
2 files changed, 134 insertions, 0 deletions
diff --git a/vendor/doctrine/dbal/src/Platforms/SQLServer/Comparator.php b/vendor/doctrine/dbal/src/Platforms/SQLServer/Comparator.php
new file mode 100644
index 0000000..aa8d9fb
--- /dev/null
+++ b/vendor/doctrine/dbal/src/Platforms/SQLServer/Comparator.php
@@ -0,0 +1,50 @@
1<?php
2
3declare(strict_types=1);
4
5namespace Doctrine\DBAL\Platforms\SQLServer;
6
7use Doctrine\DBAL\Platforms\SQLServerPlatform;
8use Doctrine\DBAL\Schema\Comparator as BaseComparator;
9use Doctrine\DBAL\Schema\Table;
10use Doctrine\DBAL\Schema\TableDiff;
11
12/**
13 * Compares schemas in the context of SQL Server platform.
14 *
15 * @link https://docs.microsoft.com/en-us/sql/t-sql/statements/collations?view=sql-server-ver15
16 */
17class Comparator extends BaseComparator
18{
19 /** @internal The comparator can be only instantiated by a schema manager. */
20 public function __construct(SQLServerPlatform $platform, private readonly string $databaseCollation)
21 {
22 parent::__construct($platform);
23 }
24
25 public function compareTables(Table $oldTable, Table $newTable): TableDiff
26 {
27 return parent::compareTables(
28 $this->normalizeColumns($oldTable),
29 $this->normalizeColumns($newTable),
30 );
31 }
32
33 private function normalizeColumns(Table $table): Table
34 {
35 $table = clone $table;
36
37 foreach ($table->getColumns() as $column) {
38 $options = $column->getPlatformOptions();
39
40 if (! isset($options['collation']) || $options['collation'] !== $this->databaseCollation) {
41 continue;
42 }
43
44 unset($options['collation']);
45 $column->setPlatformOptions($options);
46 }
47
48 return $table;
49 }
50}
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
3declare(strict_types=1);
4
5namespace Doctrine\DBAL\Platforms\SQLServer\SQL\Builder;
6
7use Doctrine\DBAL\Platforms\SQLServerPlatform;
8use Doctrine\DBAL\Query\ForUpdate\ConflictResolutionMode;
9use Doctrine\DBAL\Query\SelectQuery;
10use Doctrine\DBAL\SQL\Builder\SelectSQLBuilder;
11
12use function count;
13use function implode;
14
15final 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}