Skip to content

Commit

Permalink
feat: H2 BYTEA Values X'01' '02'
Browse files Browse the repository at this point in the history
  • Loading branch information
manticore-projects committed Sep 1, 2023
1 parent 971f353 commit 54828a4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
26 changes: 14 additions & 12 deletions src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -503,8 +503,8 @@ TOKEN : /* Numeric Constants */
)>
| < S_LONG: ( <DIGIT> )+ >
| < #DIGIT: ["0" - "9"] >
| < S_HEX: ("x'" ( <HEX_VALUE> )+ "'" | "0x" ( <HEX_VALUE> )+ ) >
| < #HEX_VALUE: ["0"-"9","A"-"F"] >
| < S_HEX: ("X" ("'" ( <HEX_VALUE> )* "'" (" ")*)+ | "0x" ( <HEX_VALUE> )+ ) >
| < #HEX_VALUE: ["0"-"9","A"-"F", " "] >
}

SPECIAL_TOKEN:
Expand Down Expand Up @@ -548,16 +548,18 @@ TOKEN:

| < #SPECIAL_ESC: "\\'" > /* Allowing this will break LIKE ... ESCAPE ... */
| < #ESC: "\\" ["n","t","b","r","f","\\","\""] >
| < S_CHAR_LITERAL: (["U","E","N","R","B"]|"RB"|"_utf8")?
(
("'" ( <ESC> | <SPECIAL_ESC> | ~["'", "\\"] )* "'") | ("'" ("''" | ~["'"])* "'")
// Alternative Oracle Escape Modes
| ("q'{" (~[])* "}'")
| ("q'(" (~[])* ")'")
| ("q'[" (~[])* "]'")
| ("q''" (~[])* "''")
// | ("q'\\" (~[])* "\\'") <--- Does not work
) >
| < S_CHAR_LITERAL: (
(["U","E","N","R","B"]|"RB"|"_utf8")?
(
("'" ( <ESC> | <SPECIAL_ESC> | ~["'", "\\"] )* "'") | ("'" ("''" | ~["'"])* "'")
// Alternative Oracle Escape Modes
| ("q'{" (~[])* "}'")
| ("q'(" (~[])* ")'")
| ("q'[" (~[])* "]'")
| ("q''" (~[])* "''")
// | ("q'\\" (~[])* "\\'") <--- Does not work
)
) >
{
// <S_CHAR_LITERAL> contains the <SPECIAL_ESC> token and always the longest match is returned
// So when Backslash is explicitly not allowed as an Escape Character and a <S_CHAR_LITERAL> is found
Expand Down
14 changes: 10 additions & 4 deletions src/test/java/net/sf/jsqlparser/expression/StringValueTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
*/
package net.sf.jsqlparser.expression;

import static org.junit.jupiter.api.Assertions.assertEquals;

import net.sf.jsqlparser.*;
import net.sf.jsqlparser.test.*;
import net.sf.jsqlparser.JSQLParserException;
import net.sf.jsqlparser.test.TestUtils;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

/**
*
* @author toben
Expand Down Expand Up @@ -87,4 +87,10 @@ public void testOracleAlternativeQuoting() throws JSQLParserException {
sqlStr = "select q'{It's good!}' from dual";
TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true);
}

@Test
public void testParseInput_BYTEA() throws Exception {
String sqlStr = "VALUES (X'', X'01FF', X'01 bc 2a', X'01' '02')";
TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true);
}
}

0 comments on commit 54828a4

Please sign in to comment.