Skip to content

Commit 06b5a52

Browse files
Merge pull request #560 from MoonE/fix-where-0
Fix where 0
2 parents 93ab20e + fe9ef88 commit 06b5a52

File tree

3 files changed

+211
-2
lines changed

3 files changed

+211
-2
lines changed

src/Components/Condition.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
153153
} else {
154154
// The expression ended.
155155
$expr->expr = trim($expr->expr);
156-
if (! empty($expr->expr)) {
156+
if ($expr->expr !== '') {
157157
$ret[] = $expr;
158158
}
159159

@@ -214,7 +214,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
214214

215215
// Last iteration was not processed.
216216
$expr->expr = trim($expr->expr);
217-
if (! empty($expr->expr)) {
217+
if ($expr->expr !== '') {
218218
$ret[] = $expr;
219219
}
220220

tests/data/parser/parseWhere0.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DELETE FROM t where 0 AND 0

tests/data/parser/parseWhere0.out

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
{
2+
"query": "DELETE FROM t where 0 AND 0",
3+
"lexer": {
4+
"@type": "PhpMyAdmin\\SqlParser\\Lexer",
5+
"str": "DELETE FROM t where 0 AND 0",
6+
"len": 27,
7+
"last": 27,
8+
"list": {
9+
"@type": "PhpMyAdmin\\SqlParser\\TokensList",
10+
"tokens": [
11+
{
12+
"@type": "PhpMyAdmin\\SqlParser\\Token",
13+
"token": "DELETE",
14+
"value": "DELETE",
15+
"keyword": "DELETE",
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": "FROM",
32+
"value": "FROM",
33+
"keyword": "FROM",
34+
"type": 1,
35+
"flags": 3,
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": 11
46+
},
47+
{
48+
"@type": "PhpMyAdmin\\SqlParser\\Token",
49+
"token": "t",
50+
"value": "t",
51+
"keyword": null,
52+
"type": 0,
53+
"flags": 0,
54+
"position": 12
55+
},
56+
{
57+
"@type": "PhpMyAdmin\\SqlParser\\Token",
58+
"token": " ",
59+
"value": " ",
60+
"keyword": null,
61+
"type": 3,
62+
"flags": 0,
63+
"position": 13
64+
},
65+
{
66+
"@type": "PhpMyAdmin\\SqlParser\\Token",
67+
"token": "where",
68+
"value": "WHERE",
69+
"keyword": "WHERE",
70+
"type": 1,
71+
"flags": 3,
72+
"position": 14
73+
},
74+
{
75+
"@type": "PhpMyAdmin\\SqlParser\\Token",
76+
"token": " ",
77+
"value": " ",
78+
"keyword": null,
79+
"type": 3,
80+
"flags": 0,
81+
"position": 19
82+
},
83+
{
84+
"@type": "PhpMyAdmin\\SqlParser\\Token",
85+
"token": "0",
86+
"value": 0,
87+
"keyword": null,
88+
"type": 6,
89+
"flags": 0,
90+
"position": 20
91+
},
92+
{
93+
"@type": "PhpMyAdmin\\SqlParser\\Token",
94+
"token": " ",
95+
"value": " ",
96+
"keyword": null,
97+
"type": 3,
98+
"flags": 0,
99+
"position": 21
100+
},
101+
{
102+
"@type": "PhpMyAdmin\\SqlParser\\Token",
103+
"token": "AND",
104+
"value": "AND",
105+
"keyword": "AND",
106+
"type": 1,
107+
"flags": 3,
108+
"position": 22
109+
},
110+
{
111+
"@type": "PhpMyAdmin\\SqlParser\\Token",
112+
"token": " ",
113+
"value": " ",
114+
"keyword": null,
115+
"type": 3,
116+
"flags": 0,
117+
"position": 25
118+
},
119+
{
120+
"@type": "PhpMyAdmin\\SqlParser\\Token",
121+
"token": "0",
122+
"value": 0,
123+
"keyword": null,
124+
"type": 6,
125+
"flags": 0,
126+
"position": 26
127+
},
128+
{
129+
"@type": "PhpMyAdmin\\SqlParser\\Token",
130+
"token": null,
131+
"value": null,
132+
"keyword": null,
133+
"type": 9,
134+
"flags": 0,
135+
"position": null
136+
}
137+
],
138+
"count": 14,
139+
"idx": 14
140+
},
141+
"delimiter": ";",
142+
"delimiterLen": 1,
143+
"strict": false,
144+
"errors": []
145+
},
146+
"parser": {
147+
"@type": "PhpMyAdmin\\SqlParser\\Parser",
148+
"list": {
149+
"@type": "@1"
150+
},
151+
"statements": [
152+
{
153+
"@type": "PhpMyAdmin\\SqlParser\\Statements\\DeleteStatement",
154+
"from": [
155+
{
156+
"@type": "PhpMyAdmin\\SqlParser\\Components\\Expression",
157+
"database": null,
158+
"table": "t",
159+
"column": null,
160+
"expr": "t",
161+
"alias": null,
162+
"function": null,
163+
"subquery": null
164+
}
165+
],
166+
"join": null,
167+
"using": null,
168+
"columns": null,
169+
"partition": null,
170+
"where": [
171+
{
172+
"@type": "PhpMyAdmin\\SqlParser\\Components\\Condition",
173+
"identifiers": [],
174+
"isOperator": false,
175+
"expr": "0"
176+
},
177+
{
178+
"@type": "PhpMyAdmin\\SqlParser\\Components\\Condition",
179+
"identifiers": [],
180+
"isOperator": true,
181+
"expr": "AND"
182+
},
183+
{
184+
"@type": "PhpMyAdmin\\SqlParser\\Components\\Condition",
185+
"identifiers": [],
186+
"isOperator": false,
187+
"expr": "0"
188+
}
189+
],
190+
"order": null,
191+
"limit": null,
192+
"options": {
193+
"@type": "PhpMyAdmin\\SqlParser\\Components\\OptionsArray",
194+
"options": []
195+
},
196+
"first": 0,
197+
"last": 12
198+
}
199+
],
200+
"brackets": 0,
201+
"strict": false,
202+
"errors": []
203+
},
204+
"errors": {
205+
"lexer": [],
206+
"parser": []
207+
}
208+
}

0 commit comments

Comments
 (0)