Skip to content

Commit 56438fb

Browse files
Stefan-Tribeikov
authored andcommitted
HHH-19558: Fixed support of JDBC escape syntax
1 parent 3ac4103 commit 56438fb

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

hibernate-core/src/main/java/org/hibernate/query/sql/internal/SQLQueryParser.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,21 @@ protected String substituteBrackets(String sqlQuery) throws QueryException {
8989
if (!doubleQuoted && !escaped) {
9090
singleQuoted = !singleQuoted;
9191
}
92-
result.append(ch);
92+
if (escaped) {
93+
token.append(ch);
94+
} else {
95+
result.append(ch);
96+
}
9397
break;
9498
case '"':
9599
if (!singleQuoted && !escaped) {
96100
doubleQuoted = !doubleQuoted;
97101
}
98-
result.append(ch);
102+
if (escaped) {
103+
token.append(ch);
104+
} else {
105+
result.append(ch);
106+
}
99107
break;
100108
case '{':
101109
if (!singleQuoted && !doubleQuoted) {

hibernate-core/src/test/java/org/hibernate/orm/test/sql/SQLQueryParserUnitTests.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,27 @@
2424
@SuppressWarnings("JUnitMalformedDeclaration")
2525
public class SQLQueryParserUnitTests {
2626

27+
@Test
28+
@DomainModel
29+
@SessionFactory
30+
@RequiresDialect(H2Dialect.class)
31+
void testJDBCEscapeSyntaxParsing(SessionFactoryScope scope) {
32+
final SessionFactoryImplementor sessionFactory = scope.getSessionFactory();
33+
final String sqlQuery = "select id, name from {h-domain}the_table where date = {d '2025-06-18'}";
34+
35+
final String full = processSqlString( sqlQuery, "my_catalog", "my_schema", sessionFactory );
36+
assertThat( full ).contains( "{d '2025-06-18'}" );
37+
38+
final String catalogOnly = processSqlString( sqlQuery, "my_catalog", null, sessionFactory );
39+
assertThat( catalogOnly ).contains( "{d '2025-06-18'}" );
40+
41+
final String schemaOnly = processSqlString( sqlQuery, null, "my_schema", sessionFactory );
42+
assertThat( schemaOnly ).contains( "{d '2025-06-18'}" );
43+
44+
final String none = processSqlString( sqlQuery, null, null, sessionFactory );
45+
assertThat( none ).contains( "{d '2025-06-18'}" );
46+
}
47+
2748
@Test
2849
@DomainModel
2950
@SessionFactory

0 commit comments

Comments
 (0)