[jOOQ/jOOQ#8737] Fix date arithmetic does not support fractional seconds

Date arithmetic now uses strftime(), so that fractional seconds don't
get trimmed.
This commit is contained in:
Knut Wannheden 2019-06-05 09:47:07 +02:00
parent 37727bee41
commit 56ee881246
2 changed files with 4 additions and 4 deletions

View File

@ -176,7 +176,7 @@ final class DateAdd<T> extends AbstractFunction<T> {
default: throwUnsupported();
}
return DSL.field("{datetime}({0}, '+' || {1} || {2})", getDataType(), date, interval, inline(keyword));
return DSL.field("{strftime}('%Y-%m-%d %H:%M:%f', {0}, {1})", getDataType(), date, interval.concat(inline(keyword)));
}

View File

@ -376,7 +376,7 @@ final class Expression<T> extends AbstractFunction<T> {
interval = interval.neg();
interval = interval.concat(inline(ytm ? " months" : " seconds"));
return DSL.field("{datetime}({0}, {1})", getDataType(), lhs, interval);
return DSL.field("{strftime}('%Y-%m-%d %H:%M:%f', {0}, {1})", getDataType(), lhs, interval);
}
@ -651,9 +651,9 @@ final class Expression<T> extends AbstractFunction<T> {
case SQLITE:
if (operator == ADD)
return DSL.field("{datetime}({0}, {1})", getDataType(), lhs, rhsAsNumber().concat(inline(" day")));
return DSL.field("{strftime}('%Y-%m-%d %H:%M:%f', {0}, {1})", getDataType(), lhs, rhsAsNumber().concat(inline(" day")));
else
return DSL.field("{datetime}({0}, {1})", getDataType(), lhs, rhsAsNumber().neg().concat(inline(" day")));
return DSL.field("{strftime}('%Y-%m-%d %H:%M:%f', {0}, {1})", getDataType(), lhs, rhsAsNumber().neg().concat(inline(" day")));