Skip to content

Commit 74504c5

Browse files
committed
Fix using ? as a parameter
- Fixes phpmyadmin#202 - Fixes phpmyadmin#412 - Fixes phpmyadmin#492 - Closes phpmyadmin#499 - Related to phpmyadmin#172 Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
1 parent ec459f7 commit 74504c5

File tree

12 files changed

+1607
-2
lines changed

12 files changed

+1607
-2
lines changed

src/Components/Condition.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
200200
&& (($token->type !== Token::TYPE_KEYWORD)
201201
|| ($token->flags & Token::FLAG_KEYWORD_RESERVED))
202202
&& ($token->type !== Token::TYPE_STRING)
203-
&& ($token->type !== Token::TYPE_SYMBOL)
203+
&& ($token->type !== Token::TYPE_SYMBOL || ($token->flags & Token::FLAG_SYMBOL_PARAMETER))
204204
) {
205205
continue;
206206
}

src/Components/Expression.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,8 @@ public static function parse(Parser $parser, TokensList $list, array $options =
366366
|| ! ($prev[0]->flags & Token::FLAG_KEYWORD_RESERVED))))
367367
&& (($prev[1]->type === Token::TYPE_STRING)
368368
|| ($prev[1]->type === Token::TYPE_SYMBOL
369-
&& ! ($prev[1]->flags & Token::FLAG_SYMBOL_VARIABLE))
369+
&& ! ($prev[1]->flags & Token::FLAG_SYMBOL_VARIABLE)
370+
&& ! ($prev[1]->flags & Token::FLAG_SYMBOL_PARAMETER))
370371
|| ($prev[1]->type === Token::TYPE_NONE
371372
&& $prev[1]->token !== 'OVER'))
372373
) {

tests/data/bugs/gh202.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
update tbl_customer t set t.`description`=:yp where t.id=1;

tests/data/bugs/gh202.out

Lines changed: 284 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,284 @@
1+
{
2+
"query": "update tbl_customer t set t.`description`=:yp where t.id=1;",
3+
"lexer": {
4+
"@type": "PhpMyAdmin\\SqlParser\\Lexer",
5+
"str": "update tbl_customer t set t.`description`=:yp where t.id=1;",
6+
"len": 59,
7+
"last": 59,
8+
"list": {
9+
"@type": "PhpMyAdmin\\SqlParser\\TokensList",
10+
"tokens": [
11+
{
12+
"@type": "PhpMyAdmin\\SqlParser\\Token",
13+
"token": "update",
14+
"value": "UPDATE",
15+
"keyword": "UPDATE",
16+
"type": 1,
17+
"flags": 3,
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": 6
28+
},
29+
{
30+
"@type": "PhpMyAdmin\\SqlParser\\Token",
31+
"token": "tbl_customer",
32+
"value": "tbl_customer",
33+
"keyword": null,
34+
"type": 0,
35+
"flags": 0,
36+
"position": 7
37+
},
38+
{
39+
"@type": "PhpMyAdmin\\SqlParser\\Token",
40+
"token": " ",
41+
"value": " ",
42+
"keyword": null,
43+
"type": 3,
44+
"flags": 0,
45+
"position": 19
46+
},
47+
{
48+
"@type": "PhpMyAdmin\\SqlParser\\Token",
49+
"token": "t",
50+
"value": "t",
51+
"keyword": null,
52+
"type": 0,
53+
"flags": 0,
54+
"position": 20
55+
},
56+
{
57+
"@type": "PhpMyAdmin\\SqlParser\\Token",
58+
"token": " ",
59+
"value": " ",
60+
"keyword": null,
61+
"type": 3,
62+
"flags": 0,
63+
"position": 21
64+
},
65+
{
66+
"@type": "PhpMyAdmin\\SqlParser\\Token",
67+
"token": "set",
68+
"value": "SET",
69+
"keyword": "SET",
70+
"type": 1,
71+
"flags": 11,
72+
"position": 22
73+
},
74+
{
75+
"@type": "PhpMyAdmin\\SqlParser\\Token",
76+
"token": " ",
77+
"value": " ",
78+
"keyword": null,
79+
"type": 3,
80+
"flags": 0,
81+
"position": 25
82+
},
83+
{
84+
"@type": "PhpMyAdmin\\SqlParser\\Token",
85+
"token": "t",
86+
"value": "t",
87+
"keyword": null,
88+
"type": 0,
89+
"flags": 0,
90+
"position": 26
91+
},
92+
{
93+
"@type": "PhpMyAdmin\\SqlParser\\Token",
94+
"token": ".",
95+
"value": ".",
96+
"keyword": null,
97+
"type": 2,
98+
"flags": 16,
99+
"position": 27
100+
},
101+
{
102+
"@type": "PhpMyAdmin\\SqlParser\\Token",
103+
"token": "`description`",
104+
"value": "description",
105+
"keyword": null,
106+
"type": 8,
107+
"flags": 2,
108+
"position": 28
109+
},
110+
{
111+
"@type": "PhpMyAdmin\\SqlParser\\Token",
112+
"token": "=",
113+
"value": "=",
114+
"keyword": null,
115+
"type": 2,
116+
"flags": 2,
117+
"position": 41
118+
},
119+
{
120+
"@type": "PhpMyAdmin\\SqlParser\\Token",
121+
"token": ":yp",
122+
"value": "yp",
123+
"keyword": null,
124+
"type": 8,
125+
"flags": 16,
126+
"position": 42
127+
},
128+
{
129+
"@type": "PhpMyAdmin\\SqlParser\\Token",
130+
"token": " ",
131+
"value": " ",
132+
"keyword": null,
133+
"type": 3,
134+
"flags": 0,
135+
"position": 45
136+
},
137+
{
138+
"@type": "PhpMyAdmin\\SqlParser\\Token",
139+
"token": "where",
140+
"value": "WHERE",
141+
"keyword": "WHERE",
142+
"type": 1,
143+
"flags": 3,
144+
"position": 46
145+
},
146+
{
147+
"@type": "PhpMyAdmin\\SqlParser\\Token",
148+
"token": " ",
149+
"value": " ",
150+
"keyword": null,
151+
"type": 3,
152+
"flags": 0,
153+
"position": 51
154+
},
155+
{
156+
"@type": "PhpMyAdmin\\SqlParser\\Token",
157+
"token": "t",
158+
"value": "t",
159+
"keyword": null,
160+
"type": 0,
161+
"flags": 0,
162+
"position": 52
163+
},
164+
{
165+
"@type": "PhpMyAdmin\\SqlParser\\Token",
166+
"token": ".",
167+
"value": ".",
168+
"keyword": null,
169+
"type": 2,
170+
"flags": 16,
171+
"position": 53
172+
},
173+
{
174+
"@type": "PhpMyAdmin\\SqlParser\\Token",
175+
"token": "id",
176+
"value": "id",
177+
"keyword": null,
178+
"type": 0,
179+
"flags": 0,
180+
"position": 54
181+
},
182+
{
183+
"@type": "PhpMyAdmin\\SqlParser\\Token",
184+
"token": "=",
185+
"value": "=",
186+
"keyword": null,
187+
"type": 2,
188+
"flags": 2,
189+
"position": 56
190+
},
191+
{
192+
"@type": "PhpMyAdmin\\SqlParser\\Token",
193+
"token": "1",
194+
"value": 1,
195+
"keyword": null,
196+
"type": 6,
197+
"flags": 0,
198+
"position": 57
199+
},
200+
{
201+
"@type": "PhpMyAdmin\\SqlParser\\Token",
202+
"token": ";",
203+
"value": ";",
204+
"keyword": null,
205+
"type": 9,
206+
"flags": 0,
207+
"position": 58
208+
},
209+
{
210+
"@type": "PhpMyAdmin\\SqlParser\\Token",
211+
"token": null,
212+
"value": null,
213+
"keyword": null,
214+
"type": 9,
215+
"flags": 0,
216+
"position": null
217+
}
218+
],
219+
"count": 23,
220+
"idx": 23
221+
},
222+
"delimiter": ";",
223+
"delimiterLen": 1,
224+
"strict": false,
225+
"errors": []
226+
},
227+
"parser": {
228+
"@type": "PhpMyAdmin\\SqlParser\\Parser",
229+
"list": {
230+
"@type": "@1"
231+
},
232+
"statements": [
233+
{
234+
"@type": "PhpMyAdmin\\SqlParser\\Statements\\UpdateStatement",
235+
"tables": [
236+
{
237+
"@type": "PhpMyAdmin\\SqlParser\\Components\\Expression",
238+
"database": null,
239+
"table": "tbl_customer",
240+
"column": null,
241+
"expr": "tbl_customer",
242+
"alias": "t",
243+
"function": null,
244+
"subquery": null
245+
}
246+
],
247+
"set": [
248+
{
249+
"@type": "PhpMyAdmin\\SqlParser\\Components\\SetOperation",
250+
"column": "t.`description`",
251+
"value": ":yp"
252+
}
253+
],
254+
"where": [
255+
{
256+
"@type": "PhpMyAdmin\\SqlParser\\Components\\Condition",
257+
"identifiers": [
258+
"t",
259+
"id"
260+
],
261+
"isOperator": false,
262+
"expr": "t.id=1"
263+
}
264+
],
265+
"order": null,
266+
"limit": null,
267+
"join": null,
268+
"options": {
269+
"@type": "PhpMyAdmin\\SqlParser\\Components\\OptionsArray",
270+
"options": []
271+
},
272+
"first": 0,
273+
"last": 20
274+
}
275+
],
276+
"brackets": 0,
277+
"strict": false,
278+
"errors": []
279+
},
280+
"errors": {
281+
"lexer": [],
282+
"parser": []
283+
}
284+
}

tests/data/bugs/gh412.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SELECT 1, 2, ?, 3

0 commit comments

Comments
 (0)