Skip to content

Commit 54828a4

Browse files
feat: H2 BYTEA Values X'01' '02'
- see http://www.h2database.com/html/grammar.html#bytes - fixes #1002
1 parent 971f353 commit 54828a4

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

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

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -503,8 +503,8 @@ TOKEN : /* Numeric Constants */
503503
)>
504504
| < S_LONG: ( <DIGIT> )+ >
505505
| < #DIGIT: ["0" - "9"] >
506-
| < S_HEX: ("x'" ( <HEX_VALUE> )+ "'" | "0x" ( <HEX_VALUE> )+ ) >
507-
| < #HEX_VALUE: ["0"-"9","A"-"F"] >
506+
| < S_HEX: ("X" ("'" ( <HEX_VALUE> )* "'" (" ")*)+ | "0x" ( <HEX_VALUE> )+ ) >
507+
| < #HEX_VALUE: ["0"-"9","A"-"F", " "] >
508508
}
509509

510510
SPECIAL_TOKEN:
@@ -548,16 +548,18 @@ TOKEN:
548548

549549
| < #SPECIAL_ESC: "\\'" > /* Allowing this will break LIKE ... ESCAPE ... */
550550
| < #ESC: "\\" ["n","t","b","r","f","\\","\""] >
551-
| < S_CHAR_LITERAL: (["U","E","N","R","B"]|"RB"|"_utf8")?
552-
(
553-
("'" ( <ESC> | <SPECIAL_ESC> | ~["'", "\\"] )* "'") | ("'" ("''" | ~["'"])* "'")
554-
// Alternative Oracle Escape Modes
555-
| ("q'{" (~[])* "}'")
556-
| ("q'(" (~[])* ")'")
557-
| ("q'[" (~[])* "]'")
558-
| ("q''" (~[])* "''")
559-
// | ("q'\\" (~[])* "\\'") <--- Does not work
560-
) >
551+
| < S_CHAR_LITERAL: (
552+
(["U","E","N","R","B"]|"RB"|"_utf8")?
553+
(
554+
("'" ( <ESC> | <SPECIAL_ESC> | ~["'", "\\"] )* "'") | ("'" ("''" | ~["'"])* "'")
555+
// Alternative Oracle Escape Modes
556+
| ("q'{" (~[])* "}'")
557+
| ("q'(" (~[])* ")'")
558+
| ("q'[" (~[])* "]'")
559+
| ("q''" (~[])* "''")
560+
// | ("q'\\" (~[])* "\\'") <--- Does not work
561+
)
562+
) >
561563
{
562564
// <S_CHAR_LITERAL> contains the <SPECIAL_ESC> token and always the longest match is returned
563565
// So when Backslash is explicitly not allowed as an Escape Character and a <S_CHAR_LITERAL> is found

src/test/java/net/sf/jsqlparser/expression/StringValueTest.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
*/
1010
package net.sf.jsqlparser.expression;
1111

12-
import static org.junit.jupiter.api.Assertions.assertEquals;
13-
14-
import net.sf.jsqlparser.*;
15-
import net.sf.jsqlparser.test.*;
12+
import net.sf.jsqlparser.JSQLParserException;
13+
import net.sf.jsqlparser.test.TestUtils;
1614
import org.junit.jupiter.api.Test;
1715

16+
import static org.junit.jupiter.api.Assertions.assertEquals;
17+
1818
/**
1919
*
2020
* @author toben
@@ -87,4 +87,10 @@ public void testOracleAlternativeQuoting() throws JSQLParserException {
8787
sqlStr = "select q'{It's good!}' from dual";
8888
TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true);
8989
}
90+
91+
@Test
92+
public void testParseInput_BYTEA() throws Exception {
93+
String sqlStr = "VALUES (X'', X'01FF', X'01 bc 2a', X'01' '02')";
94+
TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true);
95+
}
9096
}

0 commit comments

Comments
 (0)