Simplified handling of DurationField values on MySQL/MariaDB.
This commit is contained in:
parent
e90af8bad4
commit
3957f767bb
|
@ -1,4 +1,3 @@
|
||||||
import decimal
|
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
@ -262,12 +261,6 @@ class DatabaseOperations(BaseDatabaseOperations):
|
||||||
def binary_placeholder_sql(self, value):
|
def binary_placeholder_sql(self, value):
|
||||||
return '_binary %s' if value is not None and not hasattr(value, 'as_sql') else '%s'
|
return '_binary %s' if value is not None and not hasattr(value, 'as_sql') else '%s'
|
||||||
|
|
||||||
def convert_durationfield_value(self, value, expression, connection):
|
|
||||||
# DurationFields can return a Decimal in MariaDB.
|
|
||||||
if isinstance(value, decimal.Decimal):
|
|
||||||
value = float(value)
|
|
||||||
return super().convert_durationfield_value(value, expression, connection)
|
|
||||||
|
|
||||||
def subtract_temporals(self, internal_type, lhs, rhs):
|
def subtract_temporals(self, internal_type, lhs, rhs):
|
||||||
lhs_sql, lhs_params = lhs
|
lhs_sql, lhs_params = lhs
|
||||||
rhs_sql, rhs_params = rhs
|
rhs_sql, rhs_params = rhs
|
||||||
|
@ -275,7 +268,7 @@ class DatabaseOperations(BaseDatabaseOperations):
|
||||||
if self.connection.mysql_is_mariadb:
|
if self.connection.mysql_is_mariadb:
|
||||||
# MariaDB includes the microsecond component in TIME_TO_SEC as
|
# MariaDB includes the microsecond component in TIME_TO_SEC as
|
||||||
# a decimal. MySQL returns an integer without microseconds.
|
# a decimal. MySQL returns an integer without microseconds.
|
||||||
return '((TIME_TO_SEC(%(lhs)s) - TIME_TO_SEC(%(rhs)s)) * 1000000)' % {
|
return 'CAST((TIME_TO_SEC(%(lhs)s) - TIME_TO_SEC(%(rhs)s)) * 1000000 AS SIGNED)' % {
|
||||||
'lhs': lhs_sql, 'rhs': rhs_sql
|
'lhs': lhs_sql, 'rhs': rhs_sql
|
||||||
}, lhs_params + rhs_params
|
}, lhs_params + rhs_params
|
||||||
return (
|
return (
|
||||||
|
|
Loading…
Reference in New Issue