From 8a1768432b1ec3ecfa390ac5eb70dbfb0cff59b3 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Thu, 24 Aug 2017 14:56:09 -0400 Subject: Fixed #28552 -- Dropped support for MySQL 5.5. --- django/contrib/gis/db/backends/mysql/operations.py | 15 +------------ django/db/backends/mysql/base.py | 13 +++-------- django/db/backends/mysql/features.py | 4 ---- django/db/backends/mysql/operations.py | 26 +++++----------------- 4 files changed, 10 insertions(+), 48 deletions(-) (limited to 'django') diff --git a/django/contrib/gis/db/backends/mysql/operations.py b/django/contrib/gis/db/backends/mysql/operations.py index 12f9eff955..f336ea1fb7 100644 --- a/django/contrib/gis/db/backends/mysql/operations.py +++ b/django/contrib/gis/db/backends/mysql/operations.py @@ -15,17 +15,10 @@ class MySQLOperations(BaseSpatialOperations, DatabaseOperations): mysql = True name = 'mysql' + geom_func_prefix = 'ST_' Adapter = WKTAdapter - @cached_property - def geom_func_prefix(self): - return '' if self.is_mysql_5_5 else 'ST_' - - @cached_property - def is_mysql_5_5(self): - return self.connection.mysql_version < (5, 6, 1) - @cached_property def is_mysql_5_6(self): return self.connection.mysql_version < (5, 7, 6) @@ -56,10 +49,6 @@ class MySQLOperations(BaseSpatialOperations, DatabaseOperations): 'within': SpatialOperator(func='MBRWithin'), } - @cached_property - def function_names(self): - return {'Length': 'GLength'} if self.is_mysql_5_5 else {} - disallowed_aggregates = ( aggregates.Collect, aggregates.Extent, aggregates.Extent3D, aggregates.MakeLine, aggregates.Union, @@ -75,8 +64,6 @@ class MySQLOperations(BaseSpatialOperations, DatabaseOperations): } if self.connection.mysql_version < (5, 7, 5): unsupported.update({'AsGeoJSON', 'GeoHash', 'IsValid'}) - if self.is_mysql_5_5: - unsupported.update({'Difference', 'Distance', 'Intersection', 'SymDifference', 'Union'}) return unsupported def geo_db_type(self, f): diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py index 0e5c25fc23..1eb3677b80 100644 --- a/django/db/backends/mysql/base.py +++ b/django/db/backends/mysql/base.py @@ -97,14 +97,14 @@ class DatabaseWrapper(BaseDatabaseWrapper): # types, as strings. Column-type strings can contain format strings; they'll # be interpolated against the values of Field.__dict__ before being output. # If a column type is set to None, it won't be included in the output. - _data_types = { + data_types = { 'AutoField': 'integer AUTO_INCREMENT', 'BigAutoField': 'bigint AUTO_INCREMENT', 'BinaryField': 'longblob', 'BooleanField': 'bool', 'CharField': 'varchar(%(max_length)s)', 'DateField': 'date', - 'DateTimeField': 'datetime', + 'DateTimeField': 'datetime(6)', 'DecimalField': 'numeric(%(max_digits)s, %(decimal_places)s)', 'DurationField': 'bigint', 'FileField': 'varchar(%(max_length)s)', @@ -121,17 +121,10 @@ class DatabaseWrapper(BaseDatabaseWrapper): 'SlugField': 'varchar(%(max_length)s)', 'SmallIntegerField': 'smallint', 'TextField': 'longtext', - 'TimeField': 'time', + 'TimeField': 'time(6)', 'UUIDField': 'char(32)', } - @cached_property - def data_types(self): - if self.features.supports_microsecond_precision: - return dict(self._data_types, DateTimeField='datetime(6)', TimeField='time(6)') - else: - return self._data_types - # For these columns, MySQL doesn't: # - accept default values and implicitly treats these columns as nullable # - support a database index diff --git a/django/db/backends/mysql/features.py b/django/db/backends/mysql/features.py index 18ab088941..542b621aa9 100644 --- a/django/db/backends/mysql/features.py +++ b/django/db/backends/mysql/features.py @@ -60,10 +60,6 @@ class DatabaseFeatures(BaseDatabaseFeatures): "Confirm support for introspected foreign keys" return self._mysql_storage_engine != 'MyISAM' - @cached_property - def supports_microsecond_precision(self): - return self.connection.mysql_version >= (5, 6, 4) - @cached_property def has_zoneinfo_database(self): # Test if the time zone definitions are installed. diff --git a/django/db/backends/mysql/operations.py b/django/db/backends/mysql/operations.py index e4492f866f..474cd8d467 100644 --- a/django/db/backends/mysql/operations.py +++ b/django/db/backends/mysql/operations.py @@ -109,10 +109,7 @@ class DatabaseOperations(BaseDatabaseOperations): return "INTERVAL '%06f' SECOND_MICROSECOND" % timedelta.total_seconds() def format_for_duration_arithmetic(self, sql): - if self.connection.features.supports_microsecond_precision: - return 'INTERVAL %s MICROSECOND' % sql - else: - return 'INTERVAL FLOOR(%s / 1000000) SECOND' % sql + return 'INTERVAL %s MICROSECOND' % sql def force_no_ordering(self): """ @@ -178,10 +175,6 @@ class DatabaseOperations(BaseDatabaseOperations): value = timezone.make_naive(value, self.connection.timezone) 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 str(value) def adapt_timefield_value(self, value): @@ -258,17 +251,10 @@ class DatabaseOperations(BaseDatabaseOperations): def subtract_temporals(self, internal_type, lhs, rhs): lhs_sql, lhs_params = lhs rhs_sql, rhs_params = rhs - if self.connection.features.supports_microsecond_precision: - if internal_type == 'TimeField': - return ( - "((TIME_TO_SEC(%(lhs)s) * POW(10, 6) + MICROSECOND(%(lhs)s)) -" - " (TIME_TO_SEC(%(rhs)s) * POW(10, 6) + MICROSECOND(%(rhs)s)))" - ) % {'lhs': lhs_sql, 'rhs': rhs_sql}, lhs_params * 2 + rhs_params * 2 - else: - return "TIMESTAMPDIFF(MICROSECOND, %s, %s)" % (rhs_sql, lhs_sql), rhs_params + lhs_params - elif internal_type == 'TimeField': + if internal_type == 'TimeField': return ( - "(TIME_TO_SEC(%s) * POW(10, 6) - TIME_TO_SEC(%s) * POW(10, 6))" - ) % (lhs_sql, rhs_sql), lhs_params + rhs_params + "((TIME_TO_SEC(%(lhs)s) * POW(10, 6) + MICROSECOND(%(lhs)s)) -" + " (TIME_TO_SEC(%(rhs)s) * POW(10, 6) + MICROSECOND(%(rhs)s)))" + ) % {'lhs': lhs_sql, 'rhs': rhs_sql}, lhs_params * 2 + rhs_params * 2 else: - return "(TIMESTAMPDIFF(SECOND, %s, %s) * POW(10, 6))" % (rhs_sql, lhs_sql), rhs_params + lhs_params + return "TIMESTAMPDIFF(MICROSECOND, %s, %s)" % (rhs_sql, lhs_sql), rhs_params + lhs_params -- cgit v1.3