HHH-15102 allow -- style comments in native SQL query

This commit is contained in:
Gavin King 2024-11-27 20:44:48 +01:00
parent 39f5946bd3
commit 1287d93a5b
2 changed files with 15 additions and 1 deletions

View File

@ -69,8 +69,16 @@ public class BasicFormatterImpl implements Formatter {
while ( tokens.hasMoreTokens() ) {
token = tokens.nextToken();
lcToken = token.toLowerCase(Locale.ROOT);
if ( "-".equals(token) && result.toString().endsWith("-") ) {
do {
result.append( token );
token = tokens.nextToken();
}
while ( !"\n".equals( token ) && tokens.hasMoreTokens() );
}
lcToken = token.toLowerCase(Locale.ROOT);
switch (lcToken) {
case "'":

View File

@ -836,6 +836,12 @@ public class NativeSQLQueriesTest {
);
}
@Test @JiraKey( "HHH-15102" )
@SkipForDialect(dialectClass = MySQLDialect.class, matchSubTypes = true)
public void testCommentInSQLQuery(SessionFactoryScope scope) {
scope.inTransaction( s -> s.createNativeQuery( "select sum(1) --count(*), effectively\nfrom ORGANIZATION" ).getSingleResult() );
}
@Test
public void testTextTypeInSQLQuery(SessionFactoryScope scope) {
String description = buildLongString( 15000, 'a' );