File tree Expand file tree Collapse file tree 7 files changed +88
-1
lines changed
javacc/net/sf/jsqlparser/parser
test/java/net/sf/jsqlparser/test/select Expand file tree Collapse file tree 7 files changed +88
-1
lines changed Original file line number Diff line number Diff line change @@ -150,4 +150,6 @@ public interface ExpressionVisitor {
150150 void visit (JsonExpression jsonExpr );
151151
152152 void visit (RegExpMySQLOperator regExpMySQLOperator );
153+
154+ void visit (UserVariable var );
153155}
Original file line number Diff line number Diff line change @@ -320,4 +320,9 @@ public void visit(WithinGroupExpression wgexpr) {
320320 element .getExpression ().accept (this );
321321 }
322322 }
323+
324+ @ Override
325+ public void visit (UserVariable var ) {
326+
327+ }
323328}
Original file line number Diff line number Diff line change 1+ /*
2+ * #%L
3+ * JSQLParser library
4+ * %%
5+ * Copyright (C) 2004 - 2013 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 .expression ;
23+
24+ /**
25+ *
26+ * @author aud
27+ */
28+ public class UserVariable implements Expression {
29+
30+ private String name ;
31+
32+ /**
33+ * The name of the parameter
34+ *
35+ * @return the name of the parameter
36+ */
37+ public String getName () {
38+ return name ;
39+ }
40+
41+ public void setName (String name ) {
42+ this .name = name ;
43+ }
44+
45+ @ Override
46+ public void accept (ExpressionVisitor expressionVisitor ) {
47+ expressionVisitor .visit (this );
48+ }
49+
50+ @ Override
51+ public String toString () {
52+ return "@" + name ;
53+ }
54+ }
Original file line number Diff line number Diff line change @@ -502,4 +502,8 @@ public void visit(SelectExpressionItem item) {
502502 @ Override
503503 public void visit (WithinGroupExpression wgexpr ) {
504504 }
505+
506+ @ Override
507+ public void visit (UserVariable var ) {
508+ }
505509}
Original file line number Diff line number Diff line change @@ -520,4 +520,9 @@ public void visit(WithinGroupExpression wgexpr) {
520520 buffer .append (wgexpr .toString ());
521521 }
522522
523+ @ Override
524+ public void visit (UserVariable var ) {
525+ buffer .append (var .toString ());
526+ }
527+
523528}
Original file line number Diff line number Diff line change @@ -1733,6 +1733,8 @@ Expression PrimaryExpression():
17331733
17341734 | retval=JdbcNamedParameter()
17351735
1736+ | retval=UserVariable()
1737+
17361738 | LOOKAHEAD(AnalyticExpression()) retval=AnalyticExpression()
17371739
17381740 | LOOKAHEAD(WithinGroupExpression()) retval=WithinGroupExpression()
@@ -1788,12 +1790,23 @@ JdbcNamedParameter JdbcNamedParameter() : {
17881790 Token token;
17891791}
17901792{
1791- ":" token=<S_IDENTIFIER> { parameter.setName(token.image); }
1793+ ":" token=<S_IDENTIFIER> { parameter.setName(token.image); }
17921794 {
17931795 return parameter;
17941796 }
17951797}
17961798
1799+ UserVariable UserVariable() : {
1800+ UserVariable var = new UserVariable();
1801+ Token token;
1802+ }
1803+ {
1804+ "@" token=<S_IDENTIFIER> { var.setName(token.image); }
1805+ {
1806+ return var;
1807+ }
1808+ }
1809+
17971810JsonExpression JsonExpression() : {
17981811 JsonExpression result = new JsonExpression();
17991812 Column column;
Original file line number Diff line number Diff line change @@ -1653,4 +1653,8 @@ public void testSelectInnerWith() throws JSQLParserException {
16531653 public void testSelectWithinGroup () throws JSQLParserException {
16541654 assertSqlCanBeParsedAndDeparsed ("SELECT LISTAGG(col1, '##') WITHIN GROUP (ORDER BY col1) FROM table1" );
16551655 }
1656+
1657+ public void testSelectUserVariable () throws JSQLParserException {
1658+ assertSqlCanBeParsedAndDeparsed ("SELECT @col FROM t1" );
1659+ }
16561660}
You can’t perform that action at this time.
0 commit comments