Skip to content

Commit c916f14

Browse files
committed
fixes #116
1 parent 1808956 commit c916f14

File tree

12 files changed

+97
-15
lines changed

12 files changed

+97
-15
lines changed

src/main/java/net/sf/jsqlparser/expression/ExpressionVisitor.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,4 +152,6 @@ public interface ExpressionVisitor {
152152
void visit(RegExpMySQLOperator regExpMySQLOperator);
153153

154154
void visit(UserVariable var);
155+
156+
void visit(NumericBind bind);
155157
}

src/main/java/net/sf/jsqlparser/expression/ExpressionVisitorAdapter.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* #%L
33
* JSQLParser library
44
* %%
5-
* Copyright (C) 2004 - 2013 JSQLParser
5+
* Copyright (C) 2004 - 2015 JSQLParser
66
* %%
77
* This program is free software: you can redistribute it and/or modify
88
* it under the terms of the GNU Lesser General Public License as
@@ -325,4 +325,9 @@ public void visit(WithinGroupExpression wgexpr) {
325325
public void visit(UserVariable var) {
326326

327327
}
328+
329+
@Override
330+
public void visit(NumericBind bind) {
331+
332+
}
328333
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* #%L
3+
* JSQLParser library
4+
* %%
5+
* Copyright (C) 2004 - 2015 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 NumericBind implements Expression {
29+
30+
private int bindId;
31+
32+
public int getBindId() {
33+
return bindId;
34+
}
35+
36+
public void setBindId(int bindId) {
37+
this.bindId = bindId;
38+
}
39+
40+
@Override
41+
public void accept(ExpressionVisitor expressionVisitor) {
42+
expressionVisitor.visit(this);
43+
}
44+
45+
@Override
46+
public String toString() {
47+
return ":" + bindId;
48+
}
49+
}

src/main/java/net/sf/jsqlparser/expression/UserVariable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* #%L
33
* JSQLParser library
44
* %%
5-
* Copyright (C) 2004 - 2013 JSQLParser
5+
* Copyright (C) 2004 - 2015 JSQLParser
66
* %%
77
* This program is free software: you can redistribute it and/or modify
88
* it under the terms of the GNU Lesser General Public License as

src/main/java/net/sf/jsqlparser/util/TablesNamesFinder.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,4 +506,9 @@ public void visit(WithinGroupExpression wgexpr) {
506506
@Override
507507
public void visit(UserVariable var) {
508508
}
509+
510+
@Override
511+
public void visit(NumericBind bind) {
512+
513+
}
509514
}

src/main/java/net/sf/jsqlparser/util/deparser/ExpressionDeParser.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,4 +525,8 @@ public void visit(UserVariable var) {
525525
buffer.append(var.toString());
526526
}
527527

528+
@Override
529+
public void visit(NumericBind bind) {
530+
buffer.append(bind.toString());
531+
}
528532
}

src/main/javacc/net/sf/jsqlparser/parser/JSqlParserCC.jj

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1731,10 +1731,12 @@ Expression PrimaryExpression():
17311731

17321732
| "?" { retval = new JdbcParameter(); }
17331733

1734-
| retval=JdbcNamedParameter()
1734+
| LOOKAHEAD(2) retval=JdbcNamedParameter()
17351735

17361736
| retval=UserVariable()
17371737

1738+
| retval=NumericBind()
1739+
17381740
| LOOKAHEAD(AnalyticExpression()) retval=AnalyticExpression()
17391741

17401742
| LOOKAHEAD(WithinGroupExpression()) retval=WithinGroupExpression()
@@ -1801,8 +1803,21 @@ UserVariable UserVariable() : {
18011803
Token token;
18021804
}
18031805
{
1804-
"@" token=<S_IDENTIFIER> { var.setName(token.image); }
1806+
"@" token=<S_IDENTIFIER>
1807+
{
1808+
var.setName(token.image);
1809+
return var;
1810+
}
1811+
}
1812+
1813+
NumericBind NumericBind() : {
1814+
NumericBind var = new NumericBind();
1815+
Token token;
1816+
}
1817+
{
1818+
":" token=<S_LONG>
18051819
{
1820+
var.setBindId(Integer.valueOf(token.image));
18061821
return var;
18071822
}
18081823
}

src/test/java/net/sf/jsqlparser/test/select/SelectTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313

1414
import java.io.*;
1515
import java.util.*;
16-
import java.util.logging.Level;
17-
import java.util.logging.Logger;
1816

1917
import static net.sf.jsqlparser.test.TestUtils.*;
2018

@@ -1657,4 +1655,8 @@ public void testSelectWithinGroup() throws JSQLParserException {
16571655
public void testSelectUserVariable() throws JSQLParserException {
16581656
assertSqlCanBeParsedAndDeparsed("SELECT @col FROM t1");
16591657
}
1658+
1659+
public void testSelectNumericBind() throws JSQLParserException {
1660+
assertSqlCanBeParsedAndDeparsed("SELECT a FROM b WHERE c = :1");
1661+
}
16601662
}

src/test/java/net/sf/jsqlparser/test/select/SpecialOracleTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public void testAllSqlsParseDeparse() throws IOException {
6868
}
6969

7070
LOG.log(Level.INFO, "tested {0} files. got {1} correct parse results", new Object[]{count, success});
71-
assertTrue(success>=109);
71+
assertTrue(success>=112);
7272
}
7373

7474
@Test
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
select *
22
from a
33
where a=:3
4-
and b= : 4
5-
and c= :5and :a = :b
4+
and b= :4
5+
and c= :5 and :a = :b
66

0 commit comments

Comments
 (0)