diff options
author | Jon Dufresne <jon.dufresne@gmail.com> | 2015-04-04 12:22:30 -0700 |
---|---|---|
committer | Claude Paroz <claude@2xlibre.net> | 2015-04-06 22:43:51 +0200 |
commit | 2cf58e80d1be46ae95f77c95fe014921742295dd (patch) | |
tree | 6f26f2fbeb8f330d495437f361682bd9eb1a9b03 /django/db/backends/mysql/operations.py | |
parent | ad53213066ad25545959170f40322fa5b094989b (diff) | |
download | django-2cf58e80d1be46ae95f77c95fe014921742295dd.tar.gz |
Fixed #24584 -- Fixed microsecond handling with older MySQLdb
Diffstat (limited to 'django/db/backends/mysql/operations.py')
-rw-r--r-- | django/db/backends/mysql/operations.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/django/db/backends/mysql/operations.py b/django/db/backends/mysql/operations.py index fd468cb182..bc53f59ec5 100644 --- a/django/db/backends/mysql/operations.py +++ b/django/db/backends/mysql/operations.py @@ -77,7 +77,10 @@ class DatabaseOperations(BaseDatabaseOperations): timedelta.days, timedelta.seconds, timedelta.microseconds), [] def format_for_duration_arithmetic(self, sql): - return 'INTERVAL %s MICROSECOND' % sql + if self.connection.features.supports_microsecond_precision: + return 'INTERVAL %s MICROSECOND' % sql + else: + return 'INTERVAL FLOOR(%s / 1000000) SECOND' % sql def drop_foreignkey_sql(self): return "DROP FOREIGN KEY" @@ -146,6 +149,9 @@ class DatabaseOperations(BaseDatabaseOperations): else: raise ValueError("MySQL backend does not support timezone-aware datetimes when USE_TZ is False.") + if not self.connection.features.supports_microsecond_precision: + value = value.replace(microsecond=0) + return six.text_type(value) def value_to_db_time(self, value): |