Skip to content

Commit a6b6c9c

Browse files
committed
much better solution to problem with trim() on Informix
this problem seems to be specific to trim and not occur for other varchar functions (hope that's correct!)
1 parent 17841d6 commit a6b6c9c

File tree

2 files changed

+8
-33
lines changed

2 files changed

+8
-33
lines changed

hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/InformixDialect.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.hibernate.dialect.Replacer;
3030
import org.hibernate.dialect.SelectItemReferenceStrategy;
3131
import org.hibernate.dialect.function.InsertSubstringOverlayEmulation;
32+
import org.hibernate.dialect.function.TrimFunction;
3233
import org.hibernate.engine.jdbc.env.spi.IdentifierCaseStrategy;
3334
import org.hibernate.engine.jdbc.env.spi.IdentifierHelper;
3435
import org.hibernate.engine.jdbc.env.spi.IdentifierHelperBuilder;
@@ -393,11 +394,17 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
393394
functionRegistry.register( "overlay",
394395
new InsertSubstringOverlayEmulation( typeConfiguration, true ) );
395396

397+
// coalesce() has a bug where it does not accept parameters
398+
// as arguments, even with a cast (on Informix 14)
396399
functionRegistry.namedDescriptorBuilder( "coalesce" )
397400
.setMinArgumentCount( 1 )
398401
.setArgumentRenderingMode( SqlAstNodeRenderingMode.INLINE_PARAMETERS )
399402
.setArgumentTypeResolver( StandardFunctionArgumentTypeResolvers.ARGUMENT_OR_IMPLIED_RESULT_TYPE )
400403
.register();
404+
405+
// parameter arguments to trim() require a cast
406+
functionContributions.getFunctionRegistry().register( "trim",
407+
new TrimFunction( this, typeConfiguration, SqlAstNodeRenderingMode.NO_UNTYPED ) );
401408
}
402409

403410
@Override

hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/InformixSqlAstTranslator.java

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -191,18 +191,6 @@ else if ( expression instanceof Summarization ) {
191191
}
192192
}
193193

194-
// @Override
195-
// protected void renderNull(Literal literal) {
196-
// if ( getParameterRenderingMode() == SqlAstNodeRenderingMode.NO_UNTYPED ) {
197-
// renderCasted( literal );
198-
// }
199-
// else {
200-
// int sqlType = literal.getExpressionType().getSingleJdbcMapping().getJdbcType().getJdbcTypeCode();
201-
// String nullString = getDialect().getSelectClauseNullString( sqlType, getSessionFactory().getTypeConfiguration() );
202-
// appendSql( nullString );
203-
// }
204-
// }
205-
206194
@Override
207195
protected void renderInsertIntoNoColumns(TableInsertStandard tableInsert) {
208196
renderIntoIntoAndTable( tableInsert );
@@ -245,7 +233,7 @@ public void visitValuesTableReference(ValuesTableReference tableReference) {
245233
protected boolean shouldEmulateFetchClause(QueryPart queryPart) {
246234
// Check if current query part is already row numbering to avoid infinite recursion
247235
return useOffsetFetchClause( queryPart ) && getQueryPartForRowNumbering() != queryPart
248-
&& getDialect().supportsWindowFunctions() && !isRowsOnlyFetchClauseType( queryPart );
236+
&& getDialect().supportsWindowFunctions() && !isRowsOnlyFetchClauseType( queryPart );
249237
}
250238

251239
@Override
@@ -295,26 +283,6 @@ protected void visitArithmeticOperand(Expression expression) {
295283
}
296284
}
297285

298-
private static boolean isStringFunctionWithParameterArg(SelfRenderingExpression expression) {
299-
return expression instanceof FunctionExpression fn
300-
&& expression.getExpressionType() != null
301-
&& expression.getExpressionType().getJdbcTypeCount() == 1
302-
&& expression.getExpressionType().getSingleJdbcMapping().getJdbcType().isString()
303-
&& fn.getArguments().stream().anyMatch( arg -> arg instanceof SqmParameterInterpretation );
304-
}
305-
306-
@Override
307-
public void visitSelfRenderingExpression(SelfRenderingExpression expression) {
308-
if ( isStringFunctionWithParameterArg( expression ) ) {
309-
append( "cast(" );
310-
super.visitSelfRenderingExpression( expression );
311-
append( " as lvarchar)" );
312-
}
313-
else {
314-
super.visitSelfRenderingExpression( expression );
315-
}
316-
}
317-
318286
private static boolean isConcatFunction(Expression expression) {
319287
return expression instanceof FunctionExpression fn
320288
&& fn.getFunctionName().equals( "concat" );

0 commit comments

Comments
 (0)