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 {
150
150
void visit (JsonExpression jsonExpr );
151
151
152
152
void visit (RegExpMySQLOperator regExpMySQLOperator );
153
+
154
+ void visit (UserVariable var );
153
155
}
Original file line number Diff line number Diff line change @@ -320,4 +320,9 @@ public void visit(WithinGroupExpression wgexpr) {
320
320
element .getExpression ().accept (this );
321
321
}
322
322
}
323
+
324
+ @ Override
325
+ public void visit (UserVariable var ) {
326
+
327
+ }
323
328
}
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) {
502
502
@ Override
503
503
public void visit (WithinGroupExpression wgexpr ) {
504
504
}
505
+
506
+ @ Override
507
+ public void visit (UserVariable var ) {
508
+ }
505
509
}
Original file line number Diff line number Diff line change @@ -520,4 +520,9 @@ public void visit(WithinGroupExpression wgexpr) {
520
520
buffer .append (wgexpr .toString ());
521
521
}
522
522
523
+ @ Override
524
+ public void visit (UserVariable var ) {
525
+ buffer .append (var .toString ());
526
+ }
527
+
523
528
}
Original file line number Diff line number Diff line change @@ -1733,6 +1733,8 @@ Expression PrimaryExpression():
1733
1733
1734
1734
| retval=JdbcNamedParameter()
1735
1735
1736
+ | retval=UserVariable()
1737
+
1736
1738
| LOOKAHEAD(AnalyticExpression()) retval=AnalyticExpression()
1737
1739
1738
1740
| LOOKAHEAD(WithinGroupExpression()) retval=WithinGroupExpression()
@@ -1788,12 +1790,23 @@ JdbcNamedParameter JdbcNamedParameter() : {
1788
1790
Token token;
1789
1791
}
1790
1792
{
1791
- ":" token=<S_IDENTIFIER> { parameter.setName(token.image); }
1793
+ ":" token=<S_IDENTIFIER> { parameter.setName(token.image); }
1792
1794
{
1793
1795
return parameter;
1794
1796
}
1795
1797
}
1796
1798
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
+
1797
1810
JsonExpression JsonExpression() : {
1798
1811
JsonExpression result = new JsonExpression();
1799
1812
Column column;
Original file line number Diff line number Diff line change @@ -1653,4 +1653,8 @@ public void testSelectInnerWith() throws JSQLParserException {
1653
1653
public void testSelectWithinGroup () throws JSQLParserException {
1654
1654
assertSqlCanBeParsedAndDeparsed ("SELECT LISTAGG(col1, '##') WITHIN GROUP (ORDER BY col1) FROM table1" );
1655
1655
}
1656
+
1657
+ public void testSelectUserVariable () throws JSQLParserException {
1658
+ assertSqlCanBeParsedAndDeparsed ("SELECT @col FROM t1" );
1659
+ }
1656
1660
}
You can’t perform that action at this time.
0 commit comments