1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Fixed #24584 -- Fixed microsecond handling with older MySQLdb

This commit is contained in:
Jon Dufresne
2015-04-04 12:22:30 -07:00
committed by Claude Paroz
parent ad53213066
commit 2cf58e80d1
3 changed files with 30 additions and 5 deletions

View File

@@ -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):