summaryrefslogtreecommitdiff
path: root/vendor/doctrine/dbal/src/SQL
diff options
context:
space:
mode:
authorpolo <ordipolo@gmx.fr>2024-08-13 23:45:21 +0200
committerpolo <ordipolo@gmx.fr>2024-08-13 23:45:21 +0200
commitbf6655a534a6775d30cafa67bd801276bda1d98d (patch)
treec6381e3f6c81c33eab72508f410b165ba05f7e9c /vendor/doctrine/dbal/src/SQL
parent94d67a4b51f8e62e7d518cce26a526ae1ec48278 (diff)
downloadAppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.zip
VERSION 0.2 doctrine ORM et entités
Diffstat (limited to 'vendor/doctrine/dbal/src/SQL')
-rw-r--r--vendor/doctrine/dbal/src/SQL/Builder/CreateSchemaObjectsSQLBuilder.php73
-rw-r--r--vendor/doctrine/dbal/src/SQL/Builder/DefaultSelectSQLBuilder.php94
-rw-r--r--vendor/doctrine/dbal/src/SQL/Builder/DropSchemaObjectsSQLBuilder.php54
-rw-r--r--vendor/doctrine/dbal/src/SQL/Builder/SelectSQLBuilder.php14
-rw-r--r--vendor/doctrine/dbal/src/SQL/Parser.php129
-rw-r--r--vendor/doctrine/dbal/src/SQL/Parser/Exception.php11
-rw-r--r--vendor/doctrine/dbal/src/SQL/Parser/Exception/RegularExpressionError.php19
-rw-r--r--vendor/doctrine/dbal/src/SQL/Parser/Visitor.php28
8 files changed, 422 insertions, 0 deletions
diff --git a/vendor/doctrine/dbal/src/SQL/Builder/CreateSchemaObjectsSQLBuilder.php b/vendor/doctrine/dbal/src/SQL/Builder/CreateSchemaObjectsSQLBuilder.php
new file mode 100644
index 0000000..5f6a77a
--- /dev/null
+++ b/vendor/doctrine/dbal/src/SQL/Builder/CreateSchemaObjectsSQLBuilder.php
@@ -0,0 +1,73 @@
1<?php
2
3declare(strict_types=1);
4
5namespace Doctrine\DBAL\SQL\Builder;
6
7use Doctrine\DBAL\Platforms\AbstractPlatform;
8use Doctrine\DBAL\Schema\Schema;
9use Doctrine\DBAL\Schema\Sequence;
10use Doctrine\DBAL\Schema\Table;
11
12use function array_merge;
13
14final class CreateSchemaObjectsSQLBuilder
15{
16 public function __construct(private readonly AbstractPlatform $platform)
17 {
18 }
19
20 /** @return list<string> */
21 public function buildSQL(Schema $schema): array
22 {
23 return array_merge(
24 $this->buildNamespaceStatements($schema->getNamespaces()),
25 $this->buildSequenceStatements($schema->getSequences()),
26 $this->buildTableStatements($schema->getTables()),
27 );
28 }
29
30 /**
31 * @param list<string> $namespaces
32 *
33 * @return list<string>
34 */
35 private function buildNamespaceStatements(array $namespaces): array
36 {
37 $statements = [];
38
39 if ($this->platform->supportsSchemas()) {
40 foreach ($namespaces as $namespace) {
41 $statements[] = $this->platform->getCreateSchemaSQL($namespace);
42 }
43 }
44
45 return $statements;
46 }
47
48 /**
49 * @param list<Table> $tables
50 *
51 * @return list<string>
52 */
53 private function buildTableStatements(array $tables): array
54 {
55 return $this->platform->getCreateTablesSQL($tables);
56 }
57
58 /**
59 * @param list<Sequence> $sequences
60 *
61 * @return list<string>
62 */
63 private function buildSequenceStatements(array $sequences): array
64 {
65 $statements = [];
66
67 foreach ($sequences as $sequence) {
68 $statements[] = $this->platform->getCreateSequenceSQL($sequence);
69 }
70
71 return $statements;
72 }
73}
diff --git a/vendor/doctrine/dbal/src/SQL/Builder/DefaultSelectSQLBuilder.php b/vendor/doctrine/dbal/src/SQL/Builder/DefaultSelectSQLBuilder.php
new file mode 100644
index 0000000..a30120e
--- /dev/null
+++ b/vendor/doctrine/dbal/src/SQL/Builder/DefaultSelectSQLBuilder.php
@@ -0,0 +1,94 @@
1<?php
2
3declare(strict_types=1);
4
5namespace Doctrine\DBAL\SQL\Builder;
6
7use Doctrine\DBAL\Exception;
8use Doctrine\DBAL\Platforms\AbstractPlatform;
9use Doctrine\DBAL\Platforms\Exception\NotSupported;
10use Doctrine\DBAL\Query\ForUpdate\ConflictResolutionMode;
11use Doctrine\DBAL\Query\SelectQuery;
12
13use function count;
14use function implode;
15
16final class DefaultSelectSQLBuilder implements SelectSQLBuilder
17{
18 /** @internal The SQL builder should be instantiated only by database platforms. */
19 public function __construct(
20 private readonly AbstractPlatform $platform,
21 private readonly ?string $forUpdateSQL,
22 private readonly ?string $skipLockedSQL,
23 ) {
24 }
25
26 /** @throws Exception */
27 public function buildSQL(SelectQuery $query): string
28 {
29 $parts = ['SELECT'];
30
31 if ($query->isDistinct()) {
32 $parts[] = 'DISTINCT';
33 }
34
35 $parts[] = implode(', ', $query->getColumns());
36
37 $from = $query->getFrom();
38
39 if (count($from) > 0) {
40 $parts[] = 'FROM ' . implode(', ', $from);
41 }
42
43 $where = $query->getWhere();
44
45 if ($where !== null) {
46 $parts[] = 'WHERE ' . $where;
47 }
48
49 $groupBy = $query->getGroupBy();
50
51 if (count($groupBy) > 0) {
52 $parts[] = 'GROUP BY ' . implode(', ', $groupBy);
53 }
54
55 $having = $query->getHaving();
56
57 if ($having !== null) {
58 $parts[] = 'HAVING ' . $having;
59 }
60
61 $orderBy = $query->getOrderBy();
62
63 if (count($orderBy) > 0) {
64 $parts[] = 'ORDER BY ' . implode(', ', $orderBy);
65 }
66
67 $sql = implode(' ', $parts);
68 $limit = $query->getLimit();
69
70 if ($limit->isDefined()) {
71 $sql = $this->platform->modifyLimitQuery($sql, $limit->getMaxResults(), $limit->getFirstResult());
72 }
73
74 $forUpdate = $query->getForUpdate();
75
76 if ($forUpdate !== null) {
77 if ($this->forUpdateSQL === null) {
78 throw NotSupported::new('FOR UPDATE');
79 }
80
81 $sql .= ' ' . $this->forUpdateSQL;
82
83 if ($forUpdate->getConflictResolutionMode() === ConflictResolutionMode::SKIP_LOCKED) {
84 if ($this->skipLockedSQL === null) {
85 throw NotSupported::new('SKIP LOCKED');
86 }
87
88 $sql .= ' ' . $this->skipLockedSQL;
89 }
90 }
91
92 return $sql;
93 }
94}
diff --git a/vendor/doctrine/dbal/src/SQL/Builder/DropSchemaObjectsSQLBuilder.php b/vendor/doctrine/dbal/src/SQL/Builder/DropSchemaObjectsSQLBuilder.php
new file mode 100644
index 0000000..c038489
--- /dev/null
+++ b/vendor/doctrine/dbal/src/SQL/Builder/DropSchemaObjectsSQLBuilder.php
@@ -0,0 +1,54 @@
1<?php
2
3declare(strict_types=1);
4
5namespace Doctrine\DBAL\SQL\Builder;
6
7use Doctrine\DBAL\Platforms\AbstractPlatform;
8use Doctrine\DBAL\Schema\Schema;
9use Doctrine\DBAL\Schema\Sequence;
10use Doctrine\DBAL\Schema\Table;
11
12use function array_merge;
13
14final class DropSchemaObjectsSQLBuilder
15{
16 public function __construct(private readonly AbstractPlatform $platform)
17 {
18 }
19
20 /** @return list<string> */
21 public function buildSQL(Schema $schema): array
22 {
23 return array_merge(
24 $this->buildSequenceStatements($schema->getSequences()),
25 $this->buildTableStatements($schema->getTables()),
26 );
27 }
28
29 /**
30 * @param list<Table> $tables
31 *
32 * @return list<string>
33 */
34 private function buildTableStatements(array $tables): array
35 {
36 return $this->platform->getDropTablesSQL($tables);
37 }
38
39 /**
40 * @param list<Sequence> $sequences
41 *
42 * @return list<string>
43 */
44 private function buildSequenceStatements(array $sequences): array
45 {
46 $statements = [];
47
48 foreach ($sequences as $sequence) {
49 $statements[] = $this->platform->getDropSequenceSQL($sequence->getQuotedName($this->platform));
50 }
51
52 return $statements;
53 }
54}
diff --git a/vendor/doctrine/dbal/src/SQL/Builder/SelectSQLBuilder.php b/vendor/doctrine/dbal/src/SQL/Builder/SelectSQLBuilder.php
new file mode 100644
index 0000000..c013f96
--- /dev/null
+++ b/vendor/doctrine/dbal/src/SQL/Builder/SelectSQLBuilder.php
@@ -0,0 +1,14 @@
1<?php
2
3declare(strict_types=1);
4
5namespace Doctrine\DBAL\SQL\Builder;
6
7use Doctrine\DBAL\Exception;
8use Doctrine\DBAL\Query\SelectQuery;
9
10interface SelectSQLBuilder
11{
12 /** @throws Exception */
13 public function buildSQL(SelectQuery $query): string;
14}
diff --git a/vendor/doctrine/dbal/src/SQL/Parser.php b/vendor/doctrine/dbal/src/SQL/Parser.php
new file mode 100644
index 0000000..ad30f09
--- /dev/null
+++ b/vendor/doctrine/dbal/src/SQL/Parser.php
@@ -0,0 +1,129 @@
1<?php
2
3declare(strict_types=1);
4
5namespace Doctrine\DBAL\SQL;
6
7use Doctrine\DBAL\SQL\Parser\Exception;
8use Doctrine\DBAL\SQL\Parser\Exception\RegularExpressionError;
9use Doctrine\DBAL\SQL\Parser\Visitor;
10
11use function array_merge;
12use function assert;
13use function current;
14use function implode;
15use function key;
16use function next;
17use function preg_last_error;
18use function preg_match;
19use function reset;
20use function sprintf;
21use function strlen;
22
23use const PREG_NO_ERROR;
24
25/**
26 * The SQL parser that focuses on identifying prepared statement parameters. It implements parsing other tokens like
27 * string literals and comments only as a way to not confuse their contents with the the parameter placeholders.
28 *
29 * The parsing logic and the implementation is inspired by the PHP PDO parser.
30 *
31 * @internal
32 *
33 * @see https://github.com/php/php-src/blob/php-7.4.12/ext/pdo/pdo_sql_parser.re#L49-L69
34 */
35final class Parser
36{
37 private const SPECIAL_CHARS = ':\?\'"`\\[\\-\\/';
38
39 private const BACKTICK_IDENTIFIER = '`[^`]*`';
40 private const BRACKET_IDENTIFIER = '(?<!\b(?i:ARRAY))\[(?:[^\]])*\]';
41 private const MULTICHAR = ':{2,}';
42 private const NAMED_PARAMETER = ':[a-zA-Z0-9_]+';
43 private const POSITIONAL_PARAMETER = '(?<!\\?)\\?(?!\\?)';
44 private const ONE_LINE_COMMENT = '--[^\r\n]*';
45 private const MULTI_LINE_COMMENT = '/\*([^*]+|\*+[^/*])*\**\*/';
46 private const SPECIAL = '[' . self::SPECIAL_CHARS . ']';
47 private const OTHER = '[^' . self::SPECIAL_CHARS . ']+';
48
49 private readonly string $sqlPattern;
50
51 public function __construct(bool $mySQLStringEscaping)
52 {
53 if ($mySQLStringEscaping) {
54 $patterns = [
55 $this->getMySQLStringLiteralPattern("'"),
56 $this->getMySQLStringLiteralPattern('"'),
57 ];
58 } else {
59 $patterns = [
60 $this->getAnsiSQLStringLiteralPattern("'"),
61 $this->getAnsiSQLStringLiteralPattern('"'),
62 ];
63 }
64
65 $patterns = array_merge($patterns, [
66 self::BACKTICK_IDENTIFIER,
67 self::BRACKET_IDENTIFIER,
68 self::MULTICHAR,
69 self::ONE_LINE_COMMENT,
70 self::MULTI_LINE_COMMENT,
71 self::OTHER,
72 ]);
73
74 $this->sqlPattern = sprintf('(%s)', implode('|', $patterns));
75 }
76
77 /**
78 * Parses the given SQL statement
79 *
80 * @throws Exception
81 */
82 public function parse(string $sql, Visitor $visitor): void
83 {
84 /** @var array<string,callable> $patterns */
85 $patterns = [
86 self::NAMED_PARAMETER => static function (string $sql) use ($visitor): void {
87 $visitor->acceptNamedParameter($sql);
88 },
89 self::POSITIONAL_PARAMETER => static function (string $sql) use ($visitor): void {
90 $visitor->acceptPositionalParameter($sql);
91 },
92 $this->sqlPattern => static function (string $sql) use ($visitor): void {
93 $visitor->acceptOther($sql);
94 },
95 self::SPECIAL => static function (string $sql) use ($visitor): void {
96 $visitor->acceptOther($sql);
97 },
98 ];
99
100 $offset = 0;
101
102 while (($handler = current($patterns)) !== false) {
103 if (preg_match('~\G' . key($patterns) . '~s', $sql, $matches, 0, $offset) === 1) {
104 $handler($matches[0]);
105 reset($patterns);
106
107 $offset += strlen($matches[0]);
108 } elseif (preg_last_error() !== PREG_NO_ERROR) {
109 // @codeCoverageIgnoreStart
110 throw RegularExpressionError::new();
111 // @codeCoverageIgnoreEnd
112 } else {
113 next($patterns);
114 }
115 }
116
117 assert($offset === strlen($sql));
118 }
119
120 private function getMySQLStringLiteralPattern(string $delimiter): string
121 {
122 return $delimiter . '((\\\\.)|(?![' . $delimiter . '\\\\]).)*' . $delimiter;
123 }
124
125 private function getAnsiSQLStringLiteralPattern(string $delimiter): string
126 {
127 return $delimiter . '[^' . $delimiter . ']*' . $delimiter;
128 }
129}
diff --git a/vendor/doctrine/dbal/src/SQL/Parser/Exception.php b/vendor/doctrine/dbal/src/SQL/Parser/Exception.php
new file mode 100644
index 0000000..0c14b35
--- /dev/null
+++ b/vendor/doctrine/dbal/src/SQL/Parser/Exception.php
@@ -0,0 +1,11 @@
1<?php
2
3declare(strict_types=1);
4
5namespace Doctrine\DBAL\SQL\Parser;
6
7use Throwable;
8
9interface Exception extends Throwable
10{
11}
diff --git a/vendor/doctrine/dbal/src/SQL/Parser/Exception/RegularExpressionError.php b/vendor/doctrine/dbal/src/SQL/Parser/Exception/RegularExpressionError.php
new file mode 100644
index 0000000..81ae215
--- /dev/null
+++ b/vendor/doctrine/dbal/src/SQL/Parser/Exception/RegularExpressionError.php
@@ -0,0 +1,19 @@
1<?php
2
3declare(strict_types=1);
4
5namespace Doctrine\DBAL\SQL\Parser\Exception;
6
7use Doctrine\DBAL\SQL\Parser\Exception;
8use RuntimeException;
9
10use function preg_last_error;
11use function preg_last_error_msg;
12
13class RegularExpressionError extends RuntimeException implements Exception
14{
15 public static function new(): self
16 {
17 return new self(preg_last_error_msg(), preg_last_error());
18 }
19}
diff --git a/vendor/doctrine/dbal/src/SQL/Parser/Visitor.php b/vendor/doctrine/dbal/src/SQL/Parser/Visitor.php
new file mode 100644
index 0000000..c0b9e92
--- /dev/null
+++ b/vendor/doctrine/dbal/src/SQL/Parser/Visitor.php
@@ -0,0 +1,28 @@
1<?php
2
3declare(strict_types=1);
4
5namespace Doctrine\DBAL\SQL\Parser;
6
7/**
8 * SQL parser visitor
9 *
10 * @internal
11 */
12interface Visitor
13{
14 /**
15 * Accepts an SQL fragment containing a positional parameter
16 */
17 public function acceptPositionalParameter(string $sql): void;
18
19 /**
20 * Accepts an SQL fragment containing a named parameter
21 */
22 public function acceptNamedParameter(string $sql): void;
23
24 /**
25 * Accepts other SQL fragments
26 */
27 public function acceptOther(string $sql): void;
28}