Skip to content

Commit b8b8eea

Browse files
VladoKurucbeikov
authored andcommitted
HHH-18364 Fix for Informix function locate() error
1 parent c04b014 commit b8b8eea

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,9 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
303303
functionFactory.monthsBetween();
304304
functionFactory.stddev();
305305
functionFactory.variance();
306-
functionFactory.locate_positionSubstring();
306+
if ( getVersion().isSameOrAfter( 12 ) ) {
307+
functionFactory.locate_charindex();
308+
}
307309

308310
//coalesce() and nullif() both supported since Informix 12
309311

hibernate-core/src/test/java/org/hibernate/orm/test/hql/ASTParserLoadingTest.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.hibernate.TypeMismatchException;
2929
import org.hibernate.cfg.Configuration;
3030
import org.hibernate.cfg.Environment;
31+
import org.hibernate.community.dialect.InformixDialect;
3132
import org.hibernate.dialect.AbstractHANADialect;
3233
import org.hibernate.dialect.CockroachDialect;
3334
import org.hibernate.dialect.DB2Dialect;
@@ -3665,15 +3666,17 @@ public void testEJBQLFunctions() throws Exception {
36653666
hql = "select length(a.description) from Animal a";
36663667
session.createQuery(hql).list();
36673668

3668-
//note: postgres and db2 don't have a 3-arg form, it gets transformed to 2-args
3669-
hql = "from Animal a where locate('abc', a.description, 2) = 2";
3670-
session.createQuery(hql).list();
3669+
if ( !( getDialect() instanceof InformixDialect && getDialect().getVersion().isBefore( 12 ) ) ) {
3670+
//note: postgres and db2 don't have a 3-arg form, it gets transformed to 2-args
3671+
hql = "from Animal a where locate('abc', a.description, 2) = 2";
3672+
session.createQuery( hql ).list();
36713673

3672-
hql = "from Animal a where locate('abc', a.description) = 2";
3673-
session.createQuery(hql).list();
3674+
hql = "from Animal a where locate('abc', a.description) = 2";
3675+
session.createQuery( hql ).list();
36743676

3675-
hql = "select locate('cat', a.description, 2) from Animal a";
3676-
session.createQuery(hql).list();
3677+
hql = "select locate('cat', a.description, 2) from Animal a";
3678+
session.createQuery( hql ).list();
3679+
}
36773680

36783681
if ( !( getDialect() instanceof DB2Dialect ) ) {
36793682
hql = "from Animal a where trim(trailing '_' from a.description) = 'cat'";

0 commit comments

Comments
 (0)