fix addition of fractional second duration on SQL Server
Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
parent
9011d22315
commit
b982bf54b5
|
@ -788,10 +788,15 @@ public class SQLServerDialect extends AbstractTransactSQLDialect {
|
||||||
return 6; //microseconds!
|
return 6; //microseconds!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Even though SQL Server only supports 1/10th microsecond precision,
|
||||||
|
* we use nanosecond as the "native" precision for datetime arithmetic
|
||||||
|
* since it simplifies calculations.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public long getFractionalSecondPrecisionInNanos() {
|
public long getFractionalSecondPrecisionInNanos() {
|
||||||
// return 100; // 1/10th microsecond
|
// return 100; // 1/10th microsecond
|
||||||
return 1; // Even though SQL Server only supports 1/10th microsecond precision, use nanosecond scale for easier computation
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -823,12 +828,14 @@ public class SQLServerDialect extends AbstractTransactSQLDialect {
|
||||||
// there's no dateadd_big()) so here we need to use two
|
// there's no dateadd_big()) so here we need to use two
|
||||||
// calls to dateadd() to add a whole duration
|
// calls to dateadd() to add a whole duration
|
||||||
switch (unit) {
|
switch (unit) {
|
||||||
case NANOSECOND:
|
case NANOSECOND: //use nanosecond as the "native" precision
|
||||||
case NATIVE:
|
case NATIVE:
|
||||||
return "dateadd(nanosecond,?2%1000000000,dateadd(second,?2/1000000000,?3))";
|
return "dateadd(nanosecond,?2%1000000000,dateadd(second,?2/1000000000,?3))";
|
||||||
// case NATIVE:
|
// case NATIVE:
|
||||||
// // 1/10th microsecond is the "native" precision
|
// // we could in principle use 1/10th microsecond as the "native" precision
|
||||||
// return "dateadd(nanosecond,?2%10000000,dateadd(second,?2/10000000,?3))";
|
// return "dateadd(nanosecond,?2%10000000,dateadd(second,?2/10000000,?3))";
|
||||||
|
case SECOND:
|
||||||
|
return "dateadd(nanosecond,cast(?2*1e9 as bigint)%1000000000,dateadd(second,?2,?3))";
|
||||||
default:
|
default:
|
||||||
return "dateadd(?1,?2,?3)";
|
return "dateadd(?1,?2,?3)";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue