Skip to content

Commit 138c3a4

Browse files
VladoKurucbeikov
authored andcommitted
HHH-18364 Fix for Informix function locate() error
1 parent 23fd856 commit 138c3a4

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
@@ -11,6 +11,7 @@
1111
import org.hibernate.ScrollableResults;
1212
import org.hibernate.TypeMismatchException;
1313
import org.hibernate.cfg.Environment;
14+
import org.hibernate.community.dialect.InformixDialect;
1415
import org.hibernate.community.dialect.DerbyDialect;
1516
import org.hibernate.dialect.CockroachDialect;
1617
import org.hibernate.dialect.DB2Dialect;
@@ -3642,15 +3643,17 @@ public void testEJBQLFunctions(SessionFactoryScope scope) {
36423643
hql = "select length(a.description) from Animal a";
36433644
session.createQuery( hql ).list();
36443645

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

3649-
hql = "from Animal a where locate('abc', a.description) = 2";
3650-
session.createQuery( hql ).list();
3651+
hql = "from Animal a where locate('abc', a.description) = 2";
3652+
session.createQuery( hql ).list();
36513653

3652-
hql = "select locate('cat', a.description, 2) from Animal a";
3653-
session.createQuery( hql ).list();
3654+
hql = "select locate('cat', a.description, 2) from Animal a";
3655+
session.createQuery( hql ).list();
3656+
}
36543657

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

0 commit comments

Comments
 (0)