Skip to content

Commit 0780376

Browse files
committed
Merge #486 - Fix #306 - ":=" was not recognized as an operator just like "="
Pull-request: #486 Fixes: #306 Signed-off-by: William Desportes <williamdes@wdes.fr>
2 parents 417ef40 + 0076001 commit 0780376

File tree

4 files changed

+138
-2
lines changed

4 files changed

+138
-2
lines changed

src/Components/SetOperation.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use PhpMyAdmin\SqlParser\TokensList;
1111

1212
use function implode;
13+
use function in_array;
1314
use function is_array;
1415
use function trim;
1516

@@ -63,7 +64,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
6364
* Below are the states of the parser.
6465
*
6566
* 0 ---------------------[ col_name ]--------------------> 0
66-
* 0 ------------------------[ = ]------------------------> 1
67+
* 0 ---------------------[ = or := ]---------------------> 1
6768
* 1 -----------------------[ value ]---------------------> 1
6869
* 1 ------------------------[ , ]------------------------> 0
6970
*
@@ -104,7 +105,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
104105
}
105106

106107
if ($state === 0) {
107-
if ($token->token === '=') {
108+
if (in_array($token->token, ['=', ':='], true)) {
108109
$state = 1;
109110
} elseif ($token->value !== ',') {
110111
$expr->column .= $token->token;

tests/Parser/SetStatementTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public function setProvider(): array
3232
['parser/parseSetError1'],
3333
['parser/parseInsertIntoSet'],
3434
['parser/parseSetVariable'],
35+
['parser/parseSetVariable2'],
3536
['parser/parseSetGlobalVariable'],
3637
];
3738
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SET @foo := 1
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
{
2+
"query": "SET @foo := 1\n",
3+
"lexer": {
4+
"@type": "PhpMyAdmin\\SqlParser\\Lexer",
5+
"str": "SET @foo := 1\n",
6+
"len": 14,
7+
"last": 14,
8+
"list": {
9+
"@type": "PhpMyAdmin\\SqlParser\\TokensList",
10+
"tokens": [
11+
{
12+
"@type": "PhpMyAdmin\\SqlParser\\Token",
13+
"token": "SET",
14+
"value": "SET",
15+
"keyword": "SET",
16+
"type": 1,
17+
"flags": 11,
18+
"position": 0
19+
},
20+
{
21+
"@type": "PhpMyAdmin\\SqlParser\\Token",
22+
"token": " ",
23+
"value": " ",
24+
"keyword": null,
25+
"type": 3,
26+
"flags": 0,
27+
"position": 3
28+
},
29+
{
30+
"@type": "PhpMyAdmin\\SqlParser\\Token",
31+
"token": "@foo",
32+
"value": "foo",
33+
"keyword": null,
34+
"type": 8,
35+
"flags": 1,
36+
"position": 4
37+
},
38+
{
39+
"@type": "PhpMyAdmin\\SqlParser\\Token",
40+
"token": " ",
41+
"value": " ",
42+
"keyword": null,
43+
"type": 3,
44+
"flags": 0,
45+
"position": 8
46+
},
47+
{
48+
"@type": "PhpMyAdmin\\SqlParser\\Token",
49+
"token": ":=",
50+
"value": ":=",
51+
"keyword": null,
52+
"type": 2,
53+
"flags": 8,
54+
"position": 9
55+
},
56+
{
57+
"@type": "PhpMyAdmin\\SqlParser\\Token",
58+
"token": " ",
59+
"value": " ",
60+
"keyword": null,
61+
"type": 3,
62+
"flags": 0,
63+
"position": 11
64+
},
65+
{
66+
"@type": "PhpMyAdmin\\SqlParser\\Token",
67+
"token": "1",
68+
"value": 1,
69+
"keyword": null,
70+
"type": 6,
71+
"flags": 0,
72+
"position": 12
73+
},
74+
{
75+
"@type": "PhpMyAdmin\\SqlParser\\Token",
76+
"token": "\n",
77+
"value": " ",
78+
"keyword": null,
79+
"type": 3,
80+
"flags": 0,
81+
"position": 13
82+
},
83+
{
84+
"@type": "PhpMyAdmin\\SqlParser\\Token",
85+
"token": null,
86+
"value": null,
87+
"keyword": null,
88+
"type": 9,
89+
"flags": 0,
90+
"position": null
91+
}
92+
],
93+
"count": 9,
94+
"idx": 9
95+
},
96+
"delimiter": ";",
97+
"delimiterLen": 1,
98+
"strict": false,
99+
"errors": []
100+
},
101+
"parser": {
102+
"@type": "PhpMyAdmin\\SqlParser\\Parser",
103+
"list": {
104+
"@type": "@1"
105+
},
106+
"statements": [
107+
{
108+
"@type": "PhpMyAdmin\\SqlParser\\Statements\\SetStatement",
109+
"options": {
110+
"@type": "PhpMyAdmin\\SqlParser\\Components\\OptionsArray",
111+
"options": []
112+
},
113+
"end_options": null,
114+
"set": [
115+
{
116+
"@type": "PhpMyAdmin\\SqlParser\\Components\\SetOperation",
117+
"column": "@foo",
118+
"value": "1"
119+
}
120+
],
121+
"first": 0,
122+
"last": 7
123+
}
124+
],
125+
"brackets": 0,
126+
"strict": false,
127+
"errors": []
128+
},
129+
"errors": {
130+
"lexer": [],
131+
"parser": []
132+
}
133+
}

0 commit comments

Comments
 (0)