This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new a6b943bf970 Fix escape '\' in SQL causing DialectSQLParsingException
(#37943)
a6b943bf970 is described below
commit a6b943bf970d27a129e77e418e19fad3d20c3651
Author: Claire <[email protected]>
AuthorDate: Tue Feb 3 13:48:01 2026 +0800
Fix escape '\' in SQL causing DialectSQLParsingException (#37943)
* update escape
* release notes
---
RELEASE-NOTES.md | 1 +
.../src/main/antlr4/imports/oracle/Literals.g4 | 2 +-
.../src/main/antlr4/imports/postgresql/Literals.g4 | 3 +-
.../src/main/antlr4/imports/sql92/Literals.g4 | 2 +-
.../parser/src/main/resources/case/dml/select.xml | 87 ++++++++++++++++++++++
.../resources/sql/supported/dml/select-escape.xml | 3 +
6 files changed, 95 insertions(+), 3 deletions(-)
diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md
index d57920e809a..8d7ee36daef 100644
--- a/RELEASE-NOTES.md
+++ b/RELEASE-NOTES.md
@@ -7,6 +7,7 @@
### Bug Fixes
1. SQL Parser: Support Oracle SQL parser correctly extract REGEXP_SUBSTR
parameters - [#37924](https://github.com/apache/shardingsphere/pull/37924)
+2. SQL Parser: Fix escape '\' in SQL causing DialectSQLParsingException -
[#37943](https://github.com/apache/shardingsphere/pull/37943)
## Release 5.5.3
diff --git
a/parser/sql/engine/dialect/oracle/src/main/antlr4/imports/oracle/Literals.g4
b/parser/sql/engine/dialect/oracle/src/main/antlr4/imports/oracle/Literals.g4
index 64a4fd963ee..c4e8efacdd0 100644
---
a/parser/sql/engine/dialect/oracle/src/main/antlr4/imports/oracle/Literals.g4
+++
b/parser/sql/engine/dialect/oracle/src/main/antlr4/imports/oracle/Literals.g4
@@ -28,7 +28,7 @@ STRING_
;
SINGLE_QUOTED_TEXT
- : (SQ_ (('\\' +) | '\'\'' | ~('\'' | '\\'))* SQ_)
+ : (SQ_ ('\'\'' | ~'\'')* SQ_)
;
DOUBLE_QUOTED_TEXT
diff --git
a/parser/sql/engine/dialect/postgresql/src/main/antlr4/imports/postgresql/Literals.g4
b/parser/sql/engine/dialect/postgresql/src/main/antlr4/imports/postgresql/Literals.g4
index b47a3b3d74f..862d0d62dbd 100644
---
a/parser/sql/engine/dialect/postgresql/src/main/antlr4/imports/postgresql/Literals.g4
+++
b/parser/sql/engine/dialect/postgresql/src/main/antlr4/imports/postgresql/Literals.g4
@@ -25,7 +25,8 @@ IDENTIFIER_
;
STRING_
- : E? SQ_ ('\\'. | '\'\'' | ~('\'' | '\\'))* SQ_
+ : E SQ_ ('\\'. | '\'\'' | ~('\'' | '\\'))* SQ_
+ | SQ_ ('\'\'' | ~'\'')* SQ_
;
NUMBER_
diff --git
a/parser/sql/engine/dialect/sql92/src/main/antlr4/imports/sql92/Literals.g4
b/parser/sql/engine/dialect/sql92/src/main/antlr4/imports/sql92/Literals.g4
index bba66d71a27..b598bb1e16f 100644
--- a/parser/sql/engine/dialect/sql92/src/main/antlr4/imports/sql92/Literals.g4
+++ b/parser/sql/engine/dialect/sql92/src/main/antlr4/imports/sql92/Literals.g4
@@ -25,7 +25,7 @@ IDENTIFIER_
;
STRING_
- : (SQ_ ('\\'. | '\'\'' | ~('\'' | '\\'))* SQ_)
+ : (SQ_ ('\'\'' | ~'\'')* SQ_)
;
NUMBER_
diff --git a/test/it/parser/src/main/resources/case/dml/select.xml
b/test/it/parser/src/main/resources/case/dml/select.xml
index 1c6958ec394..c785980d3a7 100644
--- a/test/it/parser/src/main/resources/case/dml/select.xml
+++ b/test/it/parser/src/main/resources/case/dml/select.xml
@@ -3466,6 +3466,93 @@
</expr>
</where>
</select>
+
+ <select sql-case-id="select_like_escape_backslash_postgresql">
+ <from>
+ <simple-table name="t_user" start-index="14" stop-index="19" />
+ </from>
+ <projections start-index="7" stop-index="7">
+ <shorthand-projection start-index="7" stop-index="7" />
+ </projections>
+ <where start-index="21" stop-index="57">
+ <expr>
+ <binary-operation-expression start-index="27" stop-index="57">
+ <left>
+ <column name="name" start-index="27" stop-index="30" />
+ </left>
+ <operator>LIKE</operator>
+ <right>
+ <list-expression start-index="37" stop-index="57">
+ <items>
+ <literal-expression value="abc\_def"
start-index="37" stop-index="46" />
+ </items>
+ <items>
+ <literal-expression value="\" start-index="55"
stop-index="57" />
+ </items>
+ </list-expression>
+ </right>
+ </binary-operation-expression>
+ </expr>
+ </where>
+ </select>
+
+ <select sql-case-id="select_like_escape_backslash_oracle">
+ <from>
+ <simple-table name="t_user" start-index="14" stop-index="19" />
+ </from>
+ <projections start-index="7" stop-index="7">
+ <shorthand-projection start-index="7" stop-index="7" />
+ </projections>
+ <where start-index="21" stop-index="57">
+ <expr>
+ <binary-operation-expression start-index="27" stop-index="57">
+ <left>
+ <column name="name" start-index="27" stop-index="30" />
+ </left>
+ <operator>LIKE</operator>
+ <right>
+ <list-expression start-index="37" stop-index="57">
+ <items>
+ <literal-expression value="abc\_def"
start-index="37" stop-index="46" />
+ </items>
+ <items>
+ <literal-expression value="\" start-index="55"
stop-index="57" />
+ </items>
+ </list-expression>
+ </right>
+ </binary-operation-expression>
+ </expr>
+ </where>
+ </select>
+
+ <select sql-case-id="select_like_escape_backslash_sql92">
+ <from>
+ <simple-table name="t_user" start-index="14" stop-index="19" />
+ </from>
+ <projections start-index="7" stop-index="7">
+ <shorthand-projection start-index="7" stop-index="7" />
+ </projections>
+ <where start-index="21" stop-index="57">
+ <expr>
+ <binary-operation-expression start-index="27" stop-index="57">
+ <left>
+ <column name="name" start-index="27" stop-index="30" />
+ </left>
+ <operator>LIKE</operator>
+ <right>
+ <list-expression start-index="37" stop-index="57">
+ <items>
+ <literal-expression value="abc\_def"
start-index="37" stop-index="46" />
+ </items>
+ <items>
+ <literal-expression value="\" start-index="55"
stop-index="57" />
+ </items>
+ </list-expression>
+ </right>
+ </binary-operation-expression>
+ </expr>
+ </where>
+ </select>
<select sql-case-id="select_with_block_comment" >
<from>
diff --git
a/test/it/parser/src/main/resources/sql/supported/dml/select-escape.xml
b/test/it/parser/src/main/resources/sql/supported/dml/select-escape.xml
index 6591db0698d..d0e13ec1de3 100644
--- a/test/it/parser/src/main/resources/sql/supported/dml/select-escape.xml
+++ b/test/it/parser/src/main/resources/sql/supported/dml/select-escape.xml
@@ -23,4 +23,7 @@
<sql-case id="select_alias_as_single_quote_string" value="SELECT status as
'status' FROM t_order" db-types="MySQL" />
<sql-case id="select_alias_as_string_double_quote" value="SELECT status as
"status" FROM t_order" db-types="MySQL" />
<sql-case id="select_with_multi_quoted_string" value="SELECT * FROM
t_order WHERE name like "%"''"%"" db-types="MySQL" />
+ <sql-case id="select_like_escape_backslash_postgresql" value="SELECT *
FROM t_user WHERE name LIKE 'abc\_def' ESCAPE '\'" db-types="PostgreSQL" />
+ <sql-case id="select_like_escape_backslash_oracle" value="SELECT * FROM
t_user WHERE name LIKE 'abc\_def' ESCAPE '\'" db-types="Oracle" />
+ <sql-case id="select_like_escape_backslash_sql92" value="SELECT * FROM
t_user WHERE name LIKE 'abc\_def' ESCAPE '\'" db-types="SQL92" />
</sql-cases>