File tree Expand file tree Collapse file tree
main/java/net/sf/jsqlparser/expression
test/java/net/sf/jsqlparser/expression Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -46,4 +46,20 @@ public HexValue withValue(String value) {
4646 public String toString () {
4747 return value ;
4848 }
49+
50+ public String getDigits () {
51+ return value .toUpperCase ().startsWith ("0X" )
52+ ? value .substring (2 )
53+ : value .substring (2 , value .length ()-1 );
54+ }
55+
56+ public Long getLong () {
57+ return Long .parseLong (
58+ getDigits ()
59+ , 16 );
60+ }
61+
62+ public LongValue getLongValue () {
63+ return new LongValue (getLong ());
64+ }
4965}
Original file line number Diff line number Diff line change 1+ package net .sf .jsqlparser .expression ;
2+
3+ import net .sf .jsqlparser .JSQLParserException ;
4+ import net .sf .jsqlparser .parser .CCJSqlParserUtil ;
5+ import net .sf .jsqlparser .statement .select .PlainSelect ;
6+ import org .junit .jupiter .api .Assertions ;
7+ import org .junit .jupiter .api .Test ;
8+
9+ import static org .junit .jupiter .api .Assertions .*;
10+
11+ class HexValueTest {
12+
13+ @ Test
14+ void testHexCode () throws JSQLParserException {
15+ String sqlString = "SELECT 0xF001, X'00A1'" ;
16+ PlainSelect select = (PlainSelect ) CCJSqlParserUtil .parse (sqlString );
17+
18+ HexValue hex1 = (HexValue ) select .getSelectItem (0 ).getExpression ();
19+ HexValue hex2 = (HexValue ) select .getSelectItem (1 ).getExpression ();
20+
21+ Assertions .assertEquals ("F001" , hex1 .getDigits ());
22+ Assertions .assertEquals (61441 , hex1 .getLong ());
23+ Assertions .assertEquals (61441 , hex1 .getLongValue ().getValue ());
24+
25+ Assertions .assertEquals ("00A1" , hex2 .getDigits ());
26+ Assertions .assertEquals (161 , hex2 .getLong ());
27+ Assertions .assertEquals (161 , hex2 .getLongValue ().getValue ());
28+ }
29+ }
You can’t perform that action at this time.
0 commit comments