HHH-18068 fix case-insensitive Order

can't use ordinal column refs inside lower()

Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
Gavin King 2024-05-03 18:14:49 +02:00
parent bea5e4cf3d
commit 8a133ac120
2 changed files with 22 additions and 16 deletions

View File

@ -659,7 +659,9 @@ public class SqmUtil {
// ordering by an element of the select list
return new SqmSortSpecification(
new SqmAliasedNodeRef( element, builder.getIntegerType(), builder ),
order.getDirection()
order.getDirection(),
order.getNullPrecedence(),
order.isCaseInsensitive()
);
}
else {

View File

@ -4407,21 +4407,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
emulateSortSpecificationNullPrecedence( sortExpression, nullPrecedence );
}
if ( ignoreCase ) {
appendSql( dialect.getLowercaseFunction() );
appendSql( OPEN_PARENTHESIS );
}
if ( inOverOrWithinGroupClause() ) {
resolveAliasedExpression( sortExpression ).accept( this );
}
else {
sortExpression.accept( this );
}
if ( ignoreCase ) {
appendSql( CLOSE_PARENTHESIS );
}
renderSortExpression( sortExpression, ignoreCase );
if ( sortOrder == SortDirection.DESCENDING ) {
appendSql( " desc" );
@ -4436,6 +4422,24 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
}
}
protected void renderSortExpression(Expression sortExpression, boolean ignoreCase) {
if ( ignoreCase ) {
appendSql( dialect.getLowercaseFunction() );
appendSql( OPEN_PARENTHESIS );
}
if ( inOverOrWithinGroupClause() || ignoreCase ) {
resolveAliasedExpression( sortExpression ).accept( this );
}
else {
sortExpression.accept( this );
}
if ( ignoreCase ) {
appendSql( CLOSE_PARENTHESIS );
}
}
protected boolean supportsNullPrecedence() {
return dialect.supportsNullPrecedence();
}