Skip to content

Commit a900cde

Browse files
committed
Implement support for TABLE and REPLACE statements on DESCRIBE
Signed-off-by: William Desportes <williamdes@wdes.fr>
1 parent fbb763e commit a900cde

File tree

5 files changed

+424
-56
lines changed

5 files changed

+424
-56
lines changed

src/Statements/ExplainStatement.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,9 @@ public function parse(Parser $parser, TokensList $list)
154154

155155
if (
156156
$token->keyword !== 'SELECT'
157+
&& $token->keyword !== 'TABLE'
157158
&& $token->keyword !== 'INSERT'
159+
&& $token->keyword !== 'REPLACE'
158160
&& $token->keyword !== 'UPDATE'
159161
&& $token->keyword !== 'DELETE'
160162
) {

tests/data/parser/parseExplain10.out

Lines changed: 119 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,123 @@
214214
"statements": [
215215
{
216216
"@type": "PhpMyAdmin\\SqlParser\\Statements\\ExplainStatement",
217-
"bodyParser": null,
217+
"bodyParser": {
218+
"@type": "PhpMyAdmin\\SqlParser\\Parser",
219+
"list": {
220+
"@type": "PhpMyAdmin\\SqlParser\\TokensList",
221+
"tokens": [
222+
{
223+
"@type": "@4"
224+
},
225+
{
226+
"@type": "@5"
227+
},
228+
{
229+
"@type": "@6"
230+
},
231+
{
232+
"@type": "@7"
233+
},
234+
{
235+
"@type": "@8"
236+
},
237+
{
238+
"@type": "@9"
239+
},
240+
{
241+
"@type": "@10"
242+
},
243+
{
244+
"@type": "@11"
245+
},
246+
{
247+
"@type": "@12"
248+
},
249+
{
250+
"@type": "@13"
251+
},
252+
{
253+
"@type": "@14"
254+
},
255+
{
256+
"@type": "@15"
257+
},
258+
{
259+
"@type": "@16"
260+
},
261+
{
262+
"@type": "@17"
263+
},
264+
{
265+
"@type": "@18"
266+
},
267+
{
268+
"@type": "@19"
269+
},
270+
{
271+
"@type": "@20"
272+
},
273+
{
274+
"@type": "@21"
275+
},
276+
{
277+
"@type": "@22"
278+
}
279+
],
280+
"count": 19,
281+
"idx": 19
282+
},
283+
"statements": [
284+
{
285+
"@type": "PhpMyAdmin\\SqlParser\\Statements\\ReplaceStatement",
286+
"into": {
287+
"@type": "PhpMyAdmin\\SqlParser\\Components\\IntoKeyword",
288+
"type": null,
289+
"dest": {
290+
"@type": "PhpMyAdmin\\SqlParser\\Components\\Expression",
291+
"database": null,
292+
"table": "test",
293+
"column": null,
294+
"expr": "test",
295+
"alias": null,
296+
"function": null,
297+
"subquery": null
298+
},
299+
"columns": null,
300+
"values": null,
301+
"fields_options": null,
302+
"fields_keyword": null,
303+
"lines_options": null
304+
},
305+
"values": [
306+
{
307+
"@type": "PhpMyAdmin\\SqlParser\\Components\\ArrayObj",
308+
"raw": [
309+
"1",
310+
"'Old'",
311+
"'2014-08-20 18:47:00'"
312+
],
313+
"values": [
314+
"1",
315+
"Old",
316+
"2014-08-20 18:47:00"
317+
]
318+
}
319+
],
320+
"set": null,
321+
"select": null,
322+
"options": {
323+
"@type": "PhpMyAdmin\\SqlParser\\Components\\OptionsArray",
324+
"options": []
325+
},
326+
"first": 0,
327+
"last": 16
328+
}
329+
],
330+
"brackets": 0,
331+
"strict": false,
332+
"errors": []
333+
},
218334
"statementAlias": "DESC",
219335
"connectionId": null,
220336
"explainedTable": null,
@@ -223,7 +339,7 @@
223339
"options": []
224340
},
225341
"first": 0,
226-
"last": 2
342+
"last": 20
227343
}
228344
],
229345
"brackets": 0,
@@ -232,21 +348,6 @@
232348
},
233349
"errors": {
234350
"lexer": [],
235-
"parser": [
236-
[
237-
"Unexpected token.",
238-
{
239-
"@type": "@4"
240-
},
241-
0
242-
],
243-
[
244-
"Unrecognized statement type.",
245-
{
246-
"@type": "@6"
247-
},
248-
0
249-
]
250-
]
351+
"parser": []
251352
}
252353
}

tests/data/parser/parseExplain12.out

Lines changed: 119 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,123 @@
250250
"statements": [
251251
{
252252
"@type": "PhpMyAdmin\\SqlParser\\Statements\\ExplainStatement",
253-
"bodyParser": null,
253+
"bodyParser": {
254+
"@type": "PhpMyAdmin\\SqlParser\\Parser",
255+
"list": {
256+
"@type": "PhpMyAdmin\\SqlParser\\TokensList",
257+
"tokens": [
258+
{
259+
"@type": "@8"
260+
},
261+
{
262+
"@type": "@9"
263+
},
264+
{
265+
"@type": "@10"
266+
},
267+
{
268+
"@type": "@11"
269+
},
270+
{
271+
"@type": "@12"
272+
},
273+
{
274+
"@type": "@13"
275+
},
276+
{
277+
"@type": "@14"
278+
},
279+
{
280+
"@type": "@15"
281+
},
282+
{
283+
"@type": "@16"
284+
},
285+
{
286+
"@type": "@17"
287+
},
288+
{
289+
"@type": "@18"
290+
},
291+
{
292+
"@type": "@19"
293+
},
294+
{
295+
"@type": "@20"
296+
},
297+
{
298+
"@type": "@21"
299+
},
300+
{
301+
"@type": "@22"
302+
},
303+
{
304+
"@type": "@23"
305+
},
306+
{
307+
"@type": "@24"
308+
},
309+
{
310+
"@type": "@25"
311+
},
312+
{
313+
"@type": "@26"
314+
}
315+
],
316+
"count": 19,
317+
"idx": 19
318+
},
319+
"statements": [
320+
{
321+
"@type": "PhpMyAdmin\\SqlParser\\Statements\\ReplaceStatement",
322+
"into": {
323+
"@type": "PhpMyAdmin\\SqlParser\\Components\\IntoKeyword",
324+
"type": null,
325+
"dest": {
326+
"@type": "PhpMyAdmin\\SqlParser\\Components\\Expression",
327+
"database": null,
328+
"table": "test",
329+
"column": null,
330+
"expr": "test",
331+
"alias": null,
332+
"function": null,
333+
"subquery": null
334+
},
335+
"columns": null,
336+
"values": null,
337+
"fields_options": null,
338+
"fields_keyword": null,
339+
"lines_options": null
340+
},
341+
"values": [
342+
{
343+
"@type": "PhpMyAdmin\\SqlParser\\Components\\ArrayObj",
344+
"raw": [
345+
"1",
346+
"'Old'",
347+
"'2014-08-20 18:47:00'"
348+
],
349+
"values": [
350+
"1",
351+
"Old",
352+
"2014-08-20 18:47:00"
353+
]
354+
}
355+
],
356+
"set": null,
357+
"select": null,
358+
"options": {
359+
"@type": "PhpMyAdmin\\SqlParser\\Components\\OptionsArray",
360+
"options": []
361+
},
362+
"first": 0,
363+
"last": 16
364+
}
365+
],
366+
"brackets": 0,
367+
"strict": false,
368+
"errors": []
369+
},
254370
"statementAlias": "EXPLAIN",
255371
"connectionId": null,
256372
"explainedTable": null,
@@ -266,7 +382,7 @@
266382
}
267383
},
268384
"first": 0,
269-
"last": 6
385+
"last": 24
270386
}
271387
],
272388
"brackets": 0,
@@ -275,21 +391,6 @@
275391
},
276392
"errors": {
277393
"lexer": [],
278-
"parser": [
279-
[
280-
"Unexpected token.",
281-
{
282-
"@type": "@8"
283-
},
284-
0
285-
],
286-
[
287-
"Unrecognized statement type.",
288-
{
289-
"@type": "@10"
290-
},
291-
0
292-
]
293-
]
394+
"parser": []
294395
}
295396
}

0 commit comments

Comments
 (0)