Skip to content

HHH-19558: Fixed support of JDBC Escape Syntax #10369

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,21 @@ protected String substituteBrackets(String sqlQuery) throws QueryException {
if (!doubleQuoted && !escaped) {
singleQuoted = !singleQuoted;
}
result.append(ch);
if (escaped) {
token.append(ch);
} else {
result.append(ch);
}
Comment on lines 89 to +96
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would write this as:

					if (escaped) {
						token.append(ch);
					} 
					else {
						if (!doubleQuoted) {
							singleQuoted = !singleQuoted;
						}
						result.append(ch);
					}

break;
case '"':
if (!singleQuoted && !escaped) {
doubleQuoted = !doubleQuoted;
}
result.append(ch);
if (escaped) {
token.append(ch);
} else {
result.append(ch);
}
Comment on lines -98 to +106
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change? Can JDBC escapes contain double quotes?

break;
case '{':
if (!singleQuoted && !doubleQuoted) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

import static org.assertj.core.api.Assertions.assertThat;

Expand All @@ -24,6 +26,35 @@
@SuppressWarnings("JUnitMalformedDeclaration")
public class SQLQueryParserUnitTests {

@ParameterizedTest
@DomainModel
@SessionFactory
@RequiresDialect(H2Dialect.class)
@ValueSource(strings = {
"{d '2025-06-18'}",
"{t '14:00'}",
"{t '14:00:00'}",
"{ts '2025-06-18T14:00'}",
"{ts '2025-06-18T14:00:00'}",
"{ts '2025-06-18T14:00:00.123'}",
"{ts '2025-06-18T14:00:00+01:00'}"})
void testJDBCEscapeSyntaxParsing(String variant, SessionFactoryScope scope) {
final SessionFactoryImplementor sessionFactory = scope.getSessionFactory();
final String sqlQuery = "select id, name from {h-domain}the_table where date = " + variant;

final String full = processSqlString( sqlQuery, "my_catalog", "my_schema", sessionFactory );
assertThat( full ).contains( variant );

final String catalogOnly = processSqlString( sqlQuery, "my_catalog", null, sessionFactory );
assertThat( catalogOnly ).contains( variant );

final String schemaOnly = processSqlString( sqlQuery, null, "my_schema", sessionFactory );
assertThat( schemaOnly ).contains( variant );

final String none = processSqlString( sqlQuery, null, null, sessionFactory );
assertThat( none ).contains( variant );
}

@Test
@DomainModel
@SessionFactory
Expand Down
Loading