add tests for trunc() and date_trunc(), even though they're non-"standard"
see https://hibernate.atlassian.net/browse/HHH-15855
This commit is contained in:
parent
b704e3154e
commit
f5f92b852a
|
@ -276,6 +276,8 @@ public class H2Dialect extends Dialect {
|
|||
if ( useLocalTime ) {
|
||||
functionFactory.localtimeLocaltimestamp();
|
||||
}
|
||||
functionFactory.trunc();
|
||||
functionFactory.dateTrunc();
|
||||
functionFactory.bitLength();
|
||||
functionFactory.octetLength();
|
||||
functionFactory.ascii();
|
||||
|
|
|
@ -216,6 +216,7 @@ public class OracleDialect extends Dialect {
|
|||
functionFactory.bitand();
|
||||
functionFactory.lastDay();
|
||||
functionFactory.toCharNumberDateTimestamp();
|
||||
functionFactory.dateTrunc_trunc();
|
||||
functionFactory.ceiling_ceil();
|
||||
functionFactory.concat_pipeOperator();
|
||||
functionFactory.rownumRowid();
|
||||
|
|
|
@ -2448,4 +2448,13 @@ public class CommonFunctionFactory {
|
|||
.register();
|
||||
}
|
||||
|
||||
public void dateTrunc_trunc() {
|
||||
functionRegistry.patternDescriptorBuilder( "date_trunc", "trunc(?2,'?1')" )
|
||||
.setInvariantType(timestampType)
|
||||
.setExactArgumentCount( 2 )
|
||||
.setParameterTypes(TEMPORAL_UNIT, TEMPORAL)
|
||||
.setArgumentListSignature( "(TEMPORAL_UNIT field, TEMPORAL datetime)" )
|
||||
.register();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,10 +8,16 @@ package org.hibernate.orm.test.query.hql;
|
|||
|
||||
import org.hibernate.QueryException;
|
||||
import org.hibernate.dialect.CockroachDialect;
|
||||
import org.hibernate.dialect.DB2Dialect;
|
||||
import org.hibernate.dialect.DerbyDialect;
|
||||
|
||||
import org.hibernate.dialect.H2Dialect;
|
||||
import org.hibernate.dialect.MariaDBDialect;
|
||||
import org.hibernate.dialect.MySQLDialect;
|
||||
import org.hibernate.dialect.OracleDialect;
|
||||
import org.hibernate.dialect.PostgreSQLDialect;
|
||||
import org.hibernate.dialect.SQLServerDialect;
|
||||
import org.hibernate.dialect.SybaseDialect;
|
||||
import org.hibernate.dialect.TiDBDialect;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
|
@ -473,6 +479,46 @@ public class FunctionTests {
|
|||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SkipForDialect(dialectClass = MySQLDialect.class, matchSubTypes = true)
|
||||
@SkipForDialect(dialectClass = SQLServerDialect.class)
|
||||
@SkipForDialect(dialectClass = SybaseDialect.class, matchSubTypes = true)
|
||||
@SkipForDialect(dialectClass = DerbyDialect.class)
|
||||
public void testTruncFunction(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
assertThat( session.createQuery("select trunc(32.92345)").getSingleResult(), is(32d) );
|
||||
assertThat( session.createQuery("select trunc(32.92345,3)").getSingleResult(), is(32.923d) );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@RequiresDialect(MySQLDialect.class)
|
||||
@RequiresDialect(SQLServerDialect.class)
|
||||
@RequiresDialect(DB2Dialect.class)
|
||||
@RequiresDialect(H2Dialect.class)
|
||||
public void testTruncateFunction(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
assertThat( session.createQuery("select truncate(32.92345,3)").getSingleResult(), is(32.923d) );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@RequiresDialect(H2Dialect.class)
|
||||
@RequiresDialect(DB2Dialect.class)
|
||||
@RequiresDialect(OracleDialect.class)
|
||||
@RequiresDialect(PostgreSQLDialect.class)
|
||||
public void testDateTruncFunction(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
session.createQuery("select date_trunc(year,current_timestamp)").getSingleResult();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLowerUpperFunctions(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
|
|
Loading…
Reference in New Issue