make adding fractional seconds work on h2 and HSQL

Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
Gavin King 2024-05-02 15:17:19 +02:00
parent 87516a77b7
commit 5941aca7ac
4 changed files with 14 additions and 4 deletions

View File

@ -4821,7 +4821,8 @@ public abstract class Dialect implements ConversionContext, TypeContributor, Fun
public int getDefaultTimestampPrecision() {
//milliseconds or microseconds is the maximum
//for most dialects that support explicit
//precision, with the exception of DB2 which
//precision, with the exception of Oracle,
//which accepts up to 9 digits, and DB2 which
//accepts up to 12 digits!
return 6; //microseconds!
}

View File

@ -443,7 +443,11 @@ public class H2Dialect extends Dialect {
if ( intervalType != null ) {
return "(?2+?3)";
}
return "dateadd(?1,?2,?3)";
return unit == SECOND
//TODO: if we have an integral number of seconds
// (the common case) this is unnecessary
? "dateadd(nanosecond,?2*1e9,?3)"
: "dateadd(?1,?2,?3)";
}
@Override

View File

@ -300,6 +300,11 @@ public class HSQLDialect extends Dialect {
case WEEK:
pattern.append("dateadd('day',?2*7,");
break;
case SECOND:
//TODO: if we have an integral number of seconds
// (the common case) this is unnecessary
pattern.append("timestampadd(sql_tsi_frac_second, ?2*1e9,");
break;
default:
pattern.append("dateadd('?1',?2,");
}

View File

@ -1303,7 +1303,7 @@ public class FunctionTests {
// really this could and should be made work on these dialects
@SkipForDialect(dialectClass = DerbyDialect.class)
@SkipForDialect(dialectClass = SQLServerDialect.class)
@SkipForDialect(dialectClass = SybaseDialect.class)
@SkipForDialect(dialectClass = SybaseDialect.class, matchSubTypes = true)
public void testAddSecondsWithFractionalPart(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
@ -1315,7 +1315,7 @@ public class FunctionTests {
}
@Test
@SkipForDialect(dialectClass = SybaseDialect.class)
@SkipForDialect(dialectClass = SybaseDialect.class, matchSubTypes = true)
public void testAddNanoseconds(SessionFactoryScope scope) {
scope.inTransaction(
session -> {