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 {
8888 void visit (ValuesStatement values );
8989
9090 void visit (DescribeStatement describe );
91+
92+ public void visit (ExplainStatement aThis );
9193}
Original file line number Diff line number Diff line change @@ -155,4 +155,8 @@ public void visit(ValuesStatement values) {
155155 @ Override
156156 public void visit (DescribeStatement describe ) {
157157 }
158+
159+ @ Override
160+ public void visit (ExplainStatement aThis ) {
161+ }
158162}
Original file line number Diff line number Diff line change 9696import net .sf .jsqlparser .statement .Block ;
9797import net .sf .jsqlparser .statement .Commit ;
9898import net .sf .jsqlparser .statement .DescribeStatement ;
99+ import net .sf .jsqlparser .statement .ExplainStatement ;
99100import net .sf .jsqlparser .statement .SetStatement ;
100101import net .sf .jsqlparser .statement .ShowStatement ;
101102import net .sf .jsqlparser .statement .Statement ;
@@ -853,4 +854,9 @@ public void visit(ValuesStatement values) {
853854 public void visit (DescribeStatement describe ) {
854855 describe .getTable ().accept (this );
855856 }
857+
858+ @ Override
859+ public void visit (ExplainStatement explain ) {
860+ explain .getStatement ().accept (this );
861+ }
856862}
Original file line number Diff line number Diff line change 2525import net .sf .jsqlparser .statement .Block ;
2626import net .sf .jsqlparser .statement .Commit ;
2727import net .sf .jsqlparser .statement .DescribeStatement ;
28+ import net .sf .jsqlparser .statement .ExplainStatement ;
2829import net .sf .jsqlparser .statement .SetStatement ;
2930import net .sf .jsqlparser .statement .ShowStatement ;
3031import net .sf .jsqlparser .statement .Statement ;
@@ -266,4 +267,10 @@ public void visit(DescribeStatement describe) {
266267 buffer .append ("DESCRIBE " );
267268 buffer .append (describe .getTable ());
268269 }
270+
271+ @ Override
272+ public void visit (ExplainStatement explain ) {
273+ buffer .append ("EXPLAIN " );
274+ explain .getStatement ().accept (this );
275+ }
269276}
Original file line number Diff line number Diff line change @@ -190,6 +190,7 @@ TOKEN: /* SQL Keywords. prefixed with K_ to avoid name clashes */
190190| <K_EXEC: "EXEC">
191191| <K_EXECUTE: "EXECUTE">
192192| <K_EXISTS:"EXISTS">
193+ | <K_EXPLAIN:"EXPLAIN">
193194| <K_EXTRACT:"EXTRACT">
194195| <K_FETCH:"FETCH">
195196| <K_FIRST: "FIRST">
@@ -436,6 +437,8 @@ Statement SingleStatement() :
436437 stm = Comment()
437438 |
438439 stm = Describe()
440+ |
441+ stm = Explain()
439442 )
440443 { return stm; }
441444 } catch (ParseException e) {
@@ -534,6 +537,14 @@ DescribeStatement Describe(): {
534537 }
535538}
536539
540+ ExplainStatement Explain(): {
541+ Select select;
542+ } {
543+ <K_EXPLAIN> select = Select()
544+ {
545+ return new ExplainStatement(select);
546+ }
547+ }
537548
538549UseStatement Use(): {
539550 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