Skip to content

Commit 3fb6495

Browse files
VladoKurucbeikov
authored andcommitted
HHH-18364 Fix for Informix function locate() error
1 parent 01b4f8b commit 3fb6495

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
@@ -330,7 +330,9 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio
330330
functionFactory.monthsBetween();
331331
functionFactory.stddev();
332332
functionFactory.variance();
333-
functionFactory.locate_positionSubstring();
333+
if ( getVersion().isSameOrAfter( 12 ) ) {
334+
functionFactory.locate_charindex();
335+
}
334336

335337
//coalesce() and nullif() both supported since Informix 12
336338

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
@@ -26,6 +26,7 @@
2626
import org.hibernate.TypeMismatchException;
2727
import org.hibernate.cfg.Configuration;
2828
import org.hibernate.cfg.Environment;
29+
import org.hibernate.community.dialect.InformixDialect;
2930
import org.hibernate.community.dialect.DerbyDialect;
3031
import org.hibernate.dialect.HANADialect;
3132
import org.hibernate.dialect.CockroachDialect;
@@ -3664,15 +3665,17 @@ public void testEJBQLFunctions() throws Exception {
36643665
hql = "select length(a.description) from Animal a";
36653666
session.createQuery(hql).list();
36663667

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

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

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

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

0 commit comments

Comments
 (0)