HHH-17776 - Fix whitespace padding issues for literals in select expressions on Derby and HSQLDB

Signed-off-by: Jan Schatteman <jschatte@redhat.com>
This commit is contained in:
Jan Schatteman 2024-03-04 23:15:44 +01:00 committed by Christian Beikov
parent ee76f005aa
commit 955b587eb7
4 changed files with 15 additions and 5 deletions

View File

@ -232,7 +232,12 @@ public class DerbySqlAstTranslator<T extends JdbcOperation> extends AbstractSqlA
@Override @Override
protected void renderSelectExpression(Expression expression) { protected void renderSelectExpression(Expression expression) {
renderSelectExpressionWithCastedOrInlinedPlainParameters( expression ); if ( isInSubquery() && expression instanceof Literal ) {
renderCasted( expression );
}
else {
renderSelectExpressionWithCastedOrInlinedPlainParameters( expression );
}
} }
@Override @Override

View File

@ -258,7 +258,12 @@ public class HSQLSqlAstTranslator<T extends JdbcOperation> extends AbstractSqlAs
@Override @Override
protected void renderSelectExpression(Expression expression) { protected void renderSelectExpression(Expression expression) {
renderSelectExpressionWithCastedOrInlinedPlainParameters( expression ); if ( isInSubquery() && expression instanceof Literal ) {
renderCasted( expression );
}
else {
renderSelectExpressionWithCastedOrInlinedPlainParameters( expression );
}
} }
@Override @Override

View File

@ -2442,7 +2442,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
.get( 1 ) == getCurrentQueryPart(); .get( 1 ) == getCurrentQueryPart();
} }
private boolean isInSubquery() { protected boolean isInSubquery() {
return statementStack.depth() > 1 && statementStack.getCurrent() instanceof SelectStatement return statementStack.depth() > 1 && statementStack.getCurrent() instanceof SelectStatement
&& !( (SelectStatement) statementStack.getCurrent() ).getQueryPart().isRoot(); && !( (SelectStatement) statementStack.getCurrent() ).getQueryPart().isRoot();
} }

View File

@ -122,8 +122,8 @@ public class SubqueryTests {
JpaDerivedRoot<Tuple> mainQueryRoot = mainQuery.from( unionAllSubQuery ); JpaDerivedRoot<Tuple> mainQueryRoot = mainQuery.from( unionAllSubQuery );
mainQuery.multiselect( mainQuery.multiselect(
builder.trim(mainQueryRoot.get("name")).alias("name"), mainQueryRoot.get("name").alias("name"),
builder.trim(mainQueryRoot.get("surName")).alias("surName") mainQueryRoot.get("surName").alias("surName")
); );
mainQuery.orderBy( builder.asc(mainQueryRoot.get("name")) ); mainQuery.orderBy( builder.asc(mainQueryRoot.get("name")) );