1
0
mirror of https://github.com/django/django.git synced 2025-11-07 07:15:35 +00:00

Fixed #24959 -- Fixed queries using negative timedeltas on MySQL and Oracle.

This commit is contained in:
Mariusz Felisiak
2016-11-23 15:10:47 +01:00
committed by Tim Graham
parent 2742901ac2
commit b63d0c54b0
3 changed files with 23 additions and 11 deletions

View File

@@ -94,8 +94,7 @@ class DatabaseOperations(BaseDatabaseOperations):
return "TIME(%s)" % (field_name)
def date_interval_sql(self, timedelta):
return "INTERVAL '%d 0:0:%d:%d' DAY_MICROSECOND" % (
timedelta.days, timedelta.seconds, timedelta.microseconds), []
return "INTERVAL '%06f' SECOND_MICROSECOND" % (timedelta.total_seconds()), []
def format_for_duration_arithmetic(self, sql):
if self.connection.features.supports_microsecond_precision:

View File

@@ -93,16 +93,9 @@ WHEN (new.%(col_name)s IS NULL)
def date_interval_sql(self, timedelta):
"""
Implements the interval functionality for expressions
format for Oracle:
INTERVAL '3 00:03:20.000000' DAY(1) TO SECOND(6)
NUMTODSINTERVAL converts number to INTERVAL DAY TO SECOND literal.
"""
minutes, seconds = divmod(timedelta.seconds, 60)
hours, minutes = divmod(minutes, 60)
days = str(timedelta.days)
day_precision = len(days)
fmt = "INTERVAL '%s %02d:%02d:%02d.%06d' DAY(%d) TO SECOND(6)"
return fmt % (days, hours, minutes, seconds, timedelta.microseconds, day_precision), []
return "NUMTODSINTERVAL(%06f, 'SECOND')" % (timedelta.total_seconds()), []
def date_trunc_sql(self, lookup_type, field_name):
# http://docs.oracle.com/cd/B19306_01/server.102/b14200/functions230.htm#i1002084