File tree Expand file tree Collapse file tree 7 files changed +102
-0
lines changed
jjtree/net/sf/jsqlparser/parser
test/java/net/sf/jsqlparser/statement Expand file tree Collapse file tree 7 files changed +102
-0
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ * #%L
3
+ * JSQLParser library
4
+ * %%
5
+ * Copyright (C) 2004 - 2019 JSQLParser
6
+ * %%
7
+ * This program is free software: you can redistribute it and/or modify
8
+ * it under the terms of the GNU Lesser General Public License as
9
+ * published by the Free Software Foundation, either version 2.1 of the
10
+ * License, or (at your option) any later version.
11
+ *
12
+ * This program is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ * GNU General Lesser Public License for more details.
16
+ *
17
+ * You should have received a copy of the GNU General Lesser Public
18
+ * License along with this program. If not, see
19
+ * <http://www.gnu.org/licenses/lgpl-2.1.html>.
20
+ * #L%
21
+ */
22
+ package net .sf .jsqlparser .statement ;
23
+
24
+ import net .sf .jsqlparser .statement .select .Select ;
25
+
26
+ /**
27
+ *
28
+ * @author tw
29
+ */
30
+ public class ExplainStatement implements Statement {
31
+
32
+ private Select select ;
33
+
34
+ public ExplainStatement (Select select ) {
35
+ this .select = select ;
36
+ }
37
+
38
+ public Select getStatement () {
39
+ return select ;
40
+ }
41
+
42
+ public void setStatement (Select select ) {
43
+ this .select = select ;
44
+ }
45
+
46
+ @ Override
47
+ public String toString () {
48
+ return "EXPLAIN " + select .toString ();
49
+ }
50
+
51
+ @ Override
52
+ public void accept (StatementVisitor statementVisitor ) {
53
+ statementVisitor .visit (this );
54
+ }
55
+ }
Original file line number Diff line number Diff line change @@ -88,4 +88,6 @@ public interface StatementVisitor {
88
88
void visit (ValuesStatement values );
89
89
90
90
void visit (DescribeStatement describe );
91
+
92
+ public void visit (ExplainStatement aThis );
91
93
}
Original file line number Diff line number Diff line change @@ -155,4 +155,8 @@ public void visit(ValuesStatement values) {
155
155
@ Override
156
156
public void visit (DescribeStatement describe ) {
157
157
}
158
+
159
+ @ Override
160
+ public void visit (ExplainStatement aThis ) {
161
+ }
158
162
}
Original file line number Diff line number Diff line change 96
96
import net .sf .jsqlparser .statement .Block ;
97
97
import net .sf .jsqlparser .statement .Commit ;
98
98
import net .sf .jsqlparser .statement .DescribeStatement ;
99
+ import net .sf .jsqlparser .statement .ExplainStatement ;
99
100
import net .sf .jsqlparser .statement .SetStatement ;
100
101
import net .sf .jsqlparser .statement .ShowStatement ;
101
102
import net .sf .jsqlparser .statement .Statement ;
@@ -853,4 +854,9 @@ public void visit(ValuesStatement values) {
853
854
public void visit (DescribeStatement describe ) {
854
855
describe .getTable ().accept (this );
855
856
}
857
+
858
+ @ Override
859
+ public void visit (ExplainStatement explain ) {
860
+ explain .getStatement ().accept (this );
861
+ }
856
862
}
Original file line number Diff line number Diff line change 25
25
import net .sf .jsqlparser .statement .Block ;
26
26
import net .sf .jsqlparser .statement .Commit ;
27
27
import net .sf .jsqlparser .statement .DescribeStatement ;
28
+ import net .sf .jsqlparser .statement .ExplainStatement ;
28
29
import net .sf .jsqlparser .statement .SetStatement ;
29
30
import net .sf .jsqlparser .statement .ShowStatement ;
30
31
import net .sf .jsqlparser .statement .Statement ;
@@ -266,4 +267,10 @@ public void visit(DescribeStatement describe) {
266
267
buffer .append ("DESCRIBE " );
267
268
buffer .append (describe .getTable ());
268
269
}
270
+
271
+ @ Override
272
+ public void visit (ExplainStatement explain ) {
273
+ buffer .append ("EXPLAIN " );
274
+ explain .getStatement ().accept (this );
275
+ }
269
276
}
Original file line number Diff line number Diff line change @@ -190,6 +190,7 @@ TOKEN: /* SQL Keywords. prefixed with K_ to avoid name clashes */
190
190
| <K_EXEC: "EXEC">
191
191
| <K_EXECUTE: "EXECUTE">
192
192
| <K_EXISTS:"EXISTS">
193
+ | <K_EXPLAIN:"EXPLAIN">
193
194
| <K_EXTRACT:"EXTRACT">
194
195
| <K_FETCH:"FETCH">
195
196
| <K_FIRST: "FIRST">
@@ -436,6 +437,8 @@ Statement SingleStatement() :
436
437
stm = Comment()
437
438
|
438
439
stm = Describe()
440
+ |
441
+ stm = Explain()
439
442
)
440
443
{ return stm; }
441
444
} catch (ParseException e) {
@@ -534,6 +537,14 @@ DescribeStatement Describe(): {
534
537
}
535
538
}
536
539
540
+ ExplainStatement Explain(): {
541
+ Select select;
542
+ } {
543
+ <K_EXPLAIN> select = Select()
544
+ {
545
+ return new ExplainStatement(select);
546
+ }
547
+ }
537
548
538
549
UseStatement Use(): {
539
550
String name;
Original file line number Diff line number Diff line change
1
+ package net .sf .jsqlparser .statement ;
2
+
3
+ import net .sf .jsqlparser .JSQLParserException ;
4
+ import static net .sf .jsqlparser .test .TestUtils .*;
5
+ import org .junit .Test ;
6
+
7
+ /**
8
+ *
9
+ * @author tw
10
+ */
11
+ public class ExplainTest {
12
+
13
+ @ Test
14
+ public void testDescribe () throws JSQLParserException {
15
+ assertSqlCanBeParsedAndDeparsed ("EXPLAIN SELECT * FROM mytable" );
16
+ }
17
+ }
You can’t perform that action at this time.
0 commit comments