Skip to content

Commit 41fc6b5

Browse files
Merge pull request #370 from mauriciofauth/context-sql-modes
Add support for passing integers to `Context::setMode`
2 parents 9cf3396 + 504f8fb commit 41fc6b5

File tree

9 files changed

+428
-105
lines changed

9 files changed

+428
-105
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
* Add missing return types annotations
66
* Improve the WITH statements parser (#363)
7+
* Add support for passing `Context::SQL_MODE*` constants to `Context::setMode` method
8+
* Deprecate passing strings to the `Context::setMode` method
79

810
## [5.5.0] - 2021-12-08
911

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ composer require phpmyadmin/sql-parser
2424

2525
## Documentation
2626

27-
The API documentation is available at
27+
The API documentation is available at
2828
<https://develdocs.phpmyadmin.net/sql-parser/>.
2929

3030
## Usage
@@ -96,7 +96,7 @@ $query2 = $statement->build();
9696
var_dump($query2); // outputs string(19) 'SELECT * FROM `b` '
9797

9898
// Change SQL mode
99-
PhpMyAdmin\SqlParser\Context::setMode('ANSI_QUOTES');
99+
PhpMyAdmin\SqlParser\Context::setMode(PhpMyAdmin\SqlParser\Context::SQL_MODE_ANSI_QUOTES);
100100

101101
// build the query again using different quotes
102102
$query2 = $statement->build();

phpstan-baseline.neon

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,25 @@ parameters:
5656
path: src/Components/ArrayObj.php
5757

5858
-
59-
message: "#^Array \\(array\\<PhpMyAdmin\\\\SqlParser\\\\Components\\\\Expression\\>\\) does not accept PhpMyAdmin\\\\SqlParser\\\\Components\\\\Expression\\|null\\.$#"
60-
count: 3
59+
message: "#^Binary operation \"\\.\" between ' AS ' and array\\<string\\>\\|string results in an error\\.$#"
60+
count: 1
6161
path: src/Components/CaseExpression.php
6262

6363
-
64-
message: "#^Binary operation \"\\.\" between ' AS ' and array\\<string\\>\\|string results in an error\\.$#"
64+
message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Components\\\\CaseExpression\\:\\:\\$alias \\(string\\|null\\) does not accept mixed\\.$#"
6565
count: 1
6666
path: src/Components/CaseExpression.php
6767

6868
-
69-
message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Components\\\\CaseExpression\\:\\:\\$alias \\(string\\|null\\) does not accept mixed\\.$#"
69+
message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Components\\\\CaseExpression\\:\\:\\$compare_values \\(array\\<PhpMyAdmin\\\\SqlParser\\\\Components\\\\Expression\\>\\) does not accept array\\<PhpMyAdmin\\\\SqlParser\\\\Components\\\\Expression\\|null\\>\\.$#"
7070
count: 1
7171
path: src/Components/CaseExpression.php
7272

73+
-
74+
message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Components\\\\CaseExpression\\:\\:\\$results \\(array\\<PhpMyAdmin\\\\SqlParser\\\\Components\\\\Expression\\>\\) does not accept array\\<PhpMyAdmin\\\\SqlParser\\\\Components\\\\Expression\\|null\\>\\.$#"
75+
count: 2
76+
path: src/Components/CaseExpression.php
77+
7378
-
7479
message: "#^Unreachable statement \\- code above always terminates\\.$#"
7580
count: 1
@@ -251,17 +256,17 @@ parameters:
251256
path: src/Components/JoinKeyword.php
252257

253258
-
254-
message: "#^Array \\(array\\<array\\{name\\?\\: string, length\\?\\: int, order\\?\\: string\\}\\>\\) does not accept non\\-empty\\-array\\<string, mixed\\>\\.$#"
259+
message: "#^Binary operation \"\\.\" between array\\<string\\>\\|string and ' ' results in an error\\.$#"
255260
count: 1
256261
path: src/Components/Key.php
257262

258263
-
259-
message: "#^Binary operation \"\\.\" between array\\<string\\>\\|string and ' ' results in an error\\.$#"
264+
message: "#^Binary operation \"\\.\\=\" between '' and array\\<string\\>\\|string results in an error\\.$#"
260265
count: 1
261266
path: src/Components/Key.php
262267

263268
-
264-
message: "#^Binary operation \"\\.\\=\" between '' and array\\<string\\>\\|string results in an error\\.$#"
269+
message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Components\\\\Key\\:\\:\\$columns \\(array\\<array\\{name\\?\\: string, length\\?\\: int, order\\?\\: string\\}\\>\\) does not accept non\\-empty\\-array\\<array\\<string, mixed\\>\\>\\.$#"
265270
count: 1
266271
path: src/Components/Key.php
267272

@@ -345,6 +350,11 @@ parameters:
345350
count: 1
346351
path: src/Components/OptionsArray.php
347352

353+
-
354+
message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\:\\:\\$options \\(array\\<int, mixed\\>\\) does not accept array\\<int\\|string, mixed\\>\\.$#"
355+
count: 8
356+
path: src/Components/OptionsArray.php
357+
348358
-
349359
message: "#^Right side of && is always true\\.$#"
350360
count: 1
@@ -500,19 +510,14 @@ parameters:
500510
count: 1
501511
path: src/Lexer.php
502512

503-
-
504-
message: "#^Array \\(array\\<PhpMyAdmin\\\\SqlParser\\\\Statements\\\\SelectStatement\\>\\) does not accept array\\<int, PhpMyAdmin\\\\SqlParser\\\\Statements\\\\SelectStatement\\|string\\|true\\>\\.$#"
505-
count: 1
506-
path: src/Parser.php
507-
508513
-
509514
message: "#^Cannot access property \\$count on PhpMyAdmin\\\\SqlParser\\\\TokensList\\|null\\.$#"
510515
count: 1
511516
path: src/Parser.php
512517

513518
-
514519
message: "#^Cannot access property \\$idx on PhpMyAdmin\\\\SqlParser\\\\TokensList\\|null\\.$#"
515-
count: 7
520+
count: 8
516521
path: src/Parser.php
517522

518523
-
@@ -535,6 +540,11 @@ parameters:
535540
count: 3
536541
path: src/Parser.php
537542

543+
-
544+
message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Statements\\\\SelectStatement\\:\\:\\$union \\(array\\<PhpMyAdmin\\\\SqlParser\\\\Statements\\\\SelectStatement\\>\\) does not accept array\\<array\\<int, bool\\|PhpMyAdmin\\\\SqlParser\\\\Statements\\\\SelectStatement\\|string\\>\\|PhpMyAdmin\\\\SqlParser\\\\Statements\\\\SelectStatement\\>\\.$#"
545+
count: 1
546+
path: src/Parser.php
547+
538548
-
539549
message: "#^Cannot access property \\$type on PhpMyAdmin\\\\SqlParser\\\\Token\\|null\\.$#"
540550
count: 1
@@ -1131,7 +1141,7 @@ parameters:
11311141
path: tests/Parser/WithStatementTest.php
11321142

11331143
-
1134-
message: "#^Cannot access offset int on non\\-empty\\-array\\<int, string\\>\\|false\\.$#"
1144+
message: "#^Cannot access offset int\\<0, max\\> on non\\-empty\\-array\\<int, string\\>\\|false\\.$#"
11351145
count: 1
11361146
path: tests/Utils/BufferedQueryTest.php
11371147

psalm-baseline.xml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<files psalm-version="4.18.0.0">
2+
<files psalm-version="4.18.1@dda05fa913f4dc6eb3386f2f7ce5a45d37a71bcb">
33
<file src="src/Component.php">
44
<MixedReturnStatement occurrences="1">
55
<code>static::build($this)</code>
@@ -584,13 +584,9 @@
584584
<InvalidReturnType occurrences="1">
585585
<code>string|string[]</code>
586586
</InvalidReturnType>
587-
<MixedAssignment occurrences="2">
587+
<MixedAssignment occurrences="1">
588588
<code>self::$KEYWORDS</code>
589-
<code>static::$MODE</code>
590589
</MixedAssignment>
591-
<MixedOperand occurrences="1">
592-
<code>constant('static::SQL_MODE_' . $m)</code>
593-
</MixedOperand>
594590
</file>
595591
<file src="src/Contexts/ContextMariaDb100000.php">
596592
<PropertyTypeCoercion occurrences="1"/>

0 commit comments

Comments
 (0)