Skip to content

Commit c244ccb

Browse files
committed
fixes #166
1 parent 463817b commit c244ccb

File tree

8 files changed

+90
-4
lines changed

8 files changed

+90
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Also I would like to know about needed examples or documentation stuff.
3737

3838
## Extensions in the latest SNAPSHOT version 0.9.4
3939

40+
* support of hex values (**0xabc54**, **x'abc567'**) added
4041
* support of (e.g. **@@SPID**) system parameters
4142
* support of signed parameters added
4243

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,10 @@ public interface ExpressionVisitor {
6262
void visit(JdbcNamedParameter jdbcNamedParameter);
6363

6464
void visit(DoubleValue doubleValue);
65-
65+
6666
void visit(LongValue longValue);
67+
68+
void visit(HexValue hexValue);
6769

6870
void visit(DateValue dateValue);
6971

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,4 +447,9 @@ public void visit(RowConstructor rowConstructor) {
447447
expr.accept(this);
448448
}
449449
}
450+
451+
@Override
452+
public void visit(HexValue hexValue) {
453+
454+
}
450455
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
* Every number with a point or a exponential format is a DoubleValue
26+
*/
27+
public class HexValue implements Expression {
28+
29+
private String stringValue;
30+
31+
public HexValue(final String value) {
32+
String val = value;
33+
this.stringValue = val;
34+
}
35+
36+
@Override
37+
public void accept(ExpressionVisitor expressionVisitor) {
38+
expressionVisitor.visit(this);
39+
}
40+
41+
public String getValue() {
42+
return stringValue;
43+
}
44+
45+
public void setValue(String d) {
46+
stringValue = d;
47+
}
48+
49+
@Override
50+
public String toString() {
51+
return stringValue;
52+
}
53+
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,4 +622,9 @@ public void visit(RowConstructor rowConstructor) {
622622
expr.accept(this);
623623
}
624624
}
625+
626+
@Override
627+
public void visit(HexValue hexValue) {
628+
629+
}
625630
}

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,17 @@ public void visit(EqualsTo equalsTo) {
105105
@Override
106106
public void visit(Division division) {
107107
visitBinaryExpression(division, " / ");
108-
109108
}
110109

111110
@Override
112111
public void visit(DoubleValue doubleValue) {
113112
buffer.append(doubleValue.toString());
113+
}
114114

115-
}
115+
@Override
116+
public void visit(HexValue hexValue) {
117+
buffer.append(hexValue.toString());
118+
}
116119

117120
public void visitOldOracleJoinBinaryExpression(OldOracleJoinBinaryExpression expression, String operator) {
118121
if (expression.isNot()) {

src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ TOKEN : /* Numeric Constants */
234234
)>
235235
| < S_LONG: ( <DIGIT> )+ >
236236
| < #DIGIT: ["0" - "9"] >
237+
| < S_HEX: ("x'" ( <HEX_VALUE> )+ "'" | "0x" ( <HEX_VALUE> )+ ) >
238+
| < #HEX_VALUE: ["0"-"9","A"-"F"] >
237239
}
238240

239241
SPECIAL_TOKEN:
@@ -1867,6 +1869,8 @@ Expression PrimaryExpression():
18671869

18681870
| LOOKAHEAD(["+" | "-"] <S_LONG>) [sign="+" | sign="-"] token=<S_LONG> { retval = new LongValue(token.image); }
18691871

1872+
| LOOKAHEAD(["+" | "-"] <S_HEX>) [sign="+" | sign="-"] token=<S_HEX> { retval = new HexValue(token.image); }
1873+
18701874
| LOOKAHEAD(["+" | "-"] CastExpression()) [sign="+" | sign="-"] retval=CastExpression()
18711875

18721876
| LOOKAHEAD(["+" | "-"] Column()) [sign="+" | sign="-"] retval=Column()

src/test/java/net/sf/jsqlparser/test/insert/InsertTest.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import net.sf.jsqlparser.schema.Table;
1515
import net.sf.jsqlparser.statement.insert.Insert;
1616
import net.sf.jsqlparser.statement.select.PlainSelect;
17-
import net.sf.jsqlparser.statement.select.SubSelect;
1817
import static net.sf.jsqlparser.test.TestUtils.*;
1918
import static org.junit.Assert.assertNotNull;
2019
import static org.junit.Assert.assertNull;
@@ -137,4 +136,18 @@ public void testInsertWithKeywords() throws JSQLParserException {
137136
assertSqlCanBeParsedAndDeparsed("INSERT INTO kvPair (value, key) VALUES (?, ?)");
138137
}
139138

139+
@Test
140+
public void testHexValues() throws JSQLParserException {
141+
assertSqlCanBeParsedAndDeparsed("INSERT INTO TABLE2 VALUES ('1', \"DSDD\", x'EFBFBDC7AB')");
142+
}
143+
144+
@Test
145+
public void testHexValues2() throws JSQLParserException {
146+
assertSqlCanBeParsedAndDeparsed("INSERT INTO TABLE2 VALUES ('1', \"DSDD\", 0xEFBFBDC7AB)");
147+
}
148+
149+
@Test
150+
public void testHexValues3() throws JSQLParserException {
151+
assertSqlCanBeParsedAndDeparsed("INSERT INTO TABLE2 VALUES ('1', \"DSDD\", 0xabcde)");
152+
}
140153
}

0 commit comments

Comments
 (0)