Skip to content

Commit 2778f93

Browse files
committed
Merge branch '5.8.x'
2 parents 4bc1c42 + c40f718 commit 2778f93

36 files changed

Lines changed: 15962 additions & 151 deletions

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
- Support `ALGORITHM` and `LOCK` options in `ALTER TABLE` statements (#319)
2121
- Fix way end of functions, procedures and triggers' bodies is identified (#438)
2222
- Fix `enclosed by` is not recognized by the parser when `fields` is in lower case (#236)
23+
- Support `KEY` on `CreateDefinition` (#330)
24+
- Fix `CALL` statements parsing (#372)
25+
- Implement support for `LEFT JOIN`, `JOIN`, `INNER JOIN` on `UpdateStatement` (#260)
2326

2427
## [5.7.0] - 2023-01-25
2528

phpstan-baseline.neon

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,6 @@ parameters:
175175
count: 1
176176
path: src/Components/ExpressionArray.php
177177

178-
-
179-
message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Components\\\\FunctionCall\\:\\:\\$name \\(string\\|null\\) does not accept mixed\\.$#"
180-
count: 1
181-
path: src/Components/FunctionCall.php
182-
183178
-
184179
message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Components\\\\FunctionCall\\:\\:\\$parameters \\(PhpMyAdmin\\\\SqlParser\\\\Components\\\\ArrayObj\\|null\\) does not accept array\\<PhpMyAdmin\\\\SqlParser\\\\Component\\>\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\ArrayObj\\.$#"
185180
count: 1
@@ -585,11 +580,6 @@ parameters:
585580
count: 1
586581
path: src/Parser.php
587582

588-
-
589-
message: "#^Cannot access property \\$type on PhpMyAdmin\\\\SqlParser\\\\Token\\|null\\.$#"
590-
count: 1
591-
path: src/Statement.php
592-
593583
-
594584
message: "#^Offset 'class' does not exist on array\\{class\\?\\: class\\-string\\<PhpMyAdmin\\\\SqlParser\\\\Component\\>, field\\?\\: non\\-empty\\-string, options\\?\\: array\\<string, string\\>\\}\\.$#"
595585
count: 1
@@ -815,19 +805,9 @@ parameters:
815805
count: 1
816806
path: src/Statements/ReplaceStatement.php
817807

818-
-
819-
message: "#^PHPDoc type array\\<PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\>\\|null of property PhpMyAdmin\\\\SqlParser\\\\Statements\\\\SetStatement\\:\\:\\$options is not covariant with PHPDoc type PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\|null of overridden property PhpMyAdmin\\\\SqlParser\\\\Statement\\:\\:\\$options\\.$#"
820-
count: 1
821-
path: src/Statements/SetStatement.php
822-
823808
-
824809
message: "#^Parameter \\#1 \\$component of static method PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\:\\:build\\(\\) expects PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray, PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\|null given\\.$#"
825-
count: 1
826-
path: src/Statements/SetStatement.php
827-
828-
-
829-
message: "#^Parameter \\#1 \\$component of static method PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\:\\:build\\(\\) expects PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray, array\\<PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\>\\|null given\\.$#"
830-
count: 1
810+
count: 2
831811
path: src/Statements/SetStatement.php
832812

833813
-

psalm-baseline.xml

Lines changed: 6 additions & 13 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="5.9.0@8b9ad1eb9e8b7d3101f949291da2b9f7767cd163">
2+
<files psalm-version="5.11.0@c9b192ab8400fdaf04b2b13d110575adc879aa90">
33
<file src="src/Components/AlterOperation.php">
44
<ArgumentTypeCoercion>
55
<code><![CDATA[$component->partitions]]></code>
@@ -260,9 +260,9 @@
260260
</RedundantCondition>
261261
</file>
262262
<file src="src/Components/FunctionCall.php">
263-
<MixedAssignment>
264-
<code><![CDATA[$ret->name]]></code>
265-
</MixedAssignment>
263+
<MixedOperand>
264+
<code><![CDATA[$token->value]]></code>
265+
</MixedOperand>
266266
<MoreSpecificImplementedParamType>
267267
<code>$component</code>
268268
</MoreSpecificImplementedParamType>
@@ -4937,9 +4937,6 @@
49374937
<MixedAssignment>
49384938
<code>$tokenValue</code>
49394939
</MixedAssignment>
4940-
<PossiblyNullPropertyFetch>
4941-
<code><![CDATA[$list->offsetGet($list->idx)->type]]></code>
4942-
</PossiblyNullPropertyFetch>
49434940
<PossiblyUndefinedArrayOffset>
49444941
<code><![CDATA[Parser::$keywordParsers[$name]['class']]]></code>
49454942
<code><![CDATA[Parser::$keywordParsers[$name]['field']]]></code>
@@ -5186,14 +5183,9 @@
51865183
</PossiblyUnusedProperty>
51875184
</file>
51885185
<file src="src/Statements/SetStatement.php">
5189-
<InvalidArgument>
5190-
<code><![CDATA[$this->options]]></code>
5191-
</InvalidArgument>
5192-
<NonInvariantDocblockPropertyType>
5193-
<code>$options</code>
5194-
</NonInvariantDocblockPropertyType>
51955186
<PossiblyNullArgument>
51965187
<code><![CDATA[$this->endOptions]]></code>
5188+
<code><![CDATA[$this->options]]></code>
51975189
<code><![CDATA[$this->set]]></code>
51985190
</PossiblyNullArgument>
51995191
</file>
@@ -5224,6 +5216,7 @@
52245216
</file>
52255217
<file src="src/Statements/UpdateStatement.php">
52265218
<PossiblyUnusedProperty>
5219+
<code>$join</code>
52275220
<code>$set</code>
52285221
<code>$where</code>
52295222
</PossiblyUnusedProperty>

src/Components/CreateDefinition.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ final class CreateDefinition implements Component
5454
'var',
5555
],
5656
'AUTO_INCREMENT' => 3,
57+
'KEY' => 4,
5758
'PRIMARY' => 4,
5859
'PRIMARY KEY' => 4,
5960
'UNIQUE' => 4,

src/Components/FunctionCall.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
7676

7777
// End of statement.
7878
if ($token->type === Token::TYPE_DELIMITER) {
79+
--$list->idx; // Let last token to previous one to avoid "This type of clause was previously parsed."
7980
break;
8081
}
8182

@@ -85,13 +86,15 @@ public static function parse(Parser $parser, TokensList $list, array $options =
8586
}
8687

8788
if ($state === 0) {
88-
$ret->name = $token->value;
89-
$state = 1;
90-
} elseif ($state === 1) {
91-
if (($token->type === Token::TYPE_OPERATOR) && ($token->value === '(')) {
92-
$ret->parameters = ArrayObj::parse($parser, $list);
89+
if ($token->type === Token::TYPE_OPERATOR && $token->value === '(') {
90+
--$list->idx; // ArrayObj needs to start with `(`
91+
$state = 1;
92+
continue;// do not add this token to the name
9393
}
9494

95+
$ret->name .= $token->value;
96+
} elseif ($state === 1) {
97+
$ret->parameters = ArrayObj::parse($parser, $list);
9598
break;
9699
}
97100
}

src/Statement.php

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

55
namespace PhpMyAdmin\SqlParser;
66

7-
use PhpMyAdmin\SqlParser\Components\FunctionCall;
87
use PhpMyAdmin\SqlParser\Components\OptionsArray;
98
use Stringable;
109

@@ -412,13 +411,6 @@ public function parse(Parser $parser, TokensList $list)
412411
}
413412

414413
$this->after($parser, $list, $token);
415-
416-
// #223 Here may make a patch, if last is delimiter, back one
417-
if ($class !== FunctionCall::class || $list->offsetGet($list->idx)->type !== Token::TYPE_DELIMITER) {
418-
continue;
419-
}
420-
421-
--$list->idx;
422414
}
423415

424416
// This may be corrected by the parser.

src/Statements/SetStatement.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class SetStatement extends Statement
8282
/**
8383
* Options used in current statement.
8484
*
85-
* @var OptionsArray[]|null
85+
* @var OptionsArray|null
8686
*/
8787
public $options;
8888

src/Statements/UpdateStatement.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use PhpMyAdmin\SqlParser\Components\Condition;
88
use PhpMyAdmin\SqlParser\Components\Expression;
9+
use PhpMyAdmin\SqlParser\Components\JoinKeyword;
910
use PhpMyAdmin\SqlParser\Components\Limit;
1011
use PhpMyAdmin\SqlParser\Components\OrderKeyword;
1112
use PhpMyAdmin\SqlParser\Components\SetOperation;
@@ -15,6 +16,7 @@
1516
* `UPDATE` statement.
1617
*
1718
* UPDATE [LOW_PRIORITY] [IGNORE] table_reference
19+
* [INNER JOIN | LEFT JOIN | JOIN] T1 ON T1.C1 = T2.C1
1820
* SET col_name1={expr1|DEFAULT} [, col_name2={expr2|DEFAULT}] ...
1921
* [WHERE where_condition]
2022
* [ORDER BY ...]
@@ -62,6 +64,18 @@ class UpdateStatement extends Statement
6264
'UPDATE',
6365
1,
6466
],
67+
'JOIN' => [
68+
'JOIN',
69+
1,
70+
],
71+
'LEFT JOIN' => [
72+
'LEFT JOIN',
73+
1,
74+
],
75+
'INNER JOIN' => [
76+
'INNER JOIN',
77+
1,
78+
],
6579
'SET' => [
6680
'SET',
6781
3,
@@ -114,4 +128,11 @@ class UpdateStatement extends Statement
114128
* @var Limit|null
115129
*/
116130
public $limit;
131+
132+
/**
133+
* Joins.
134+
*
135+
* @var JoinKeyword[]|null
136+
*/
137+
public $join;
117138
}

tests/Builder/CallStatementTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function testBuilderShort(): void
3131

3232
public function testBuilderWithDbName(): void
3333
{
34-
$query = 'CALL foo()';
34+
$query = 'CALL mydb.foo()';
3535

3636
$parser = new Parser($query);
3737
$stmt = $parser->statements[0];
@@ -41,7 +41,7 @@ public function testBuilderWithDbName(): void
4141

4242
public function testBuilderWithDbNameShort(): void
4343
{
44-
$query = 'CALL foo';
44+
$query = 'CALL mydb.foo';
4545

4646
$parser = new Parser($query);
4747
$stmt = $parser->statements[0];
@@ -51,12 +51,12 @@ public function testBuilderWithDbNameShort(): void
5151

5252
public function testBuilderWithDbNameAndParams(): void
5353
{
54-
$query = 'CALL foo(@bar, @baz);';
54+
$query = 'CALL mydb.foo(@bar, @baz);';
5555

5656
$parser = new Parser($query);
5757
$stmt = $parser->statements[0];
5858

59-
$this->assertEquals('CALL foo(@bar,@baz)', $stmt->build());
59+
$this->assertEquals('CALL mydb.foo(@bar,@baz)', $stmt->build());
6060
}
6161

6262
public function testBuilderMultiCallsShort(): void

tests/Builder/CreateStatementTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,17 @@ public function testBuilderDefaultInt(): void
7070
);
7171
}
7272

73+
public function testBuilderWithComments(): void
74+
{
75+
$parser = new Parser('CREATE TABLE tab1 (`col1` TIMESTAMP /*!40100 DEFAULT NULL */)');
76+
$stmt = $parser->statements[0];
77+
$this->assertEquals(
78+
// TODO: fix with https://github.com/phpmyadmin/sql-parser/issues/256
79+
"CREATE TABLE tab1 (\n `col1` timestamp DEFAULT NULL\n) ",
80+
$stmt->build()
81+
);
82+
}
83+
7384
public function testBuilderCompressed(): void
7485
{
7586
$parser = new Parser('CREATE TABLE users ( user_id int ) PAGE_COMPRESSED=1 PAGE_COMPRESSION_LEVEL=9;');

0 commit comments

Comments
 (0)