Refs #29548 -- Fixed GIS tests on MariaDB

This commit is contained in:
Claude Paroz 2017-11-18 14:22:15 +01:00
parent a07a49ee32
commit c28bf990d7
3 changed files with 18 additions and 13 deletions

View File

@ -29,9 +29,10 @@ class MySQLIntrospection(DatabaseIntrospection):
return field_type, field_params return field_type, field_params
def supports_spatial_index(self, cursor, table_name): def supports_spatial_index(self, cursor, table_name):
# Supported with MyISAM, or InnoDB on MySQL 5.7.5+ # Supported with MyISAM/Aria, or InnoDB on MySQL 5.7.5+/MariaDB 10.2.2+
storage_engine = self.get_storage_engine(cursor, table_name) storage_engine = self.get_storage_engine(cursor, table_name)
return ( if storage_engine == 'InnoDB':
(storage_engine == 'InnoDB' and self.connection.mysql_version >= (5, 7, 5)) or return self.connection.mysql_version >= (
storage_engine == 'MyISAM' (10, 2, 2) if self.connection.mysql_is_mariadb else (5, 7, 5)
) )
return storage_engine in ('MyISAM', 'Aria')

View File

@ -19,10 +19,6 @@ class MySQLOperations(BaseSpatialOperations, DatabaseOperations):
Adapter = WKTAdapter Adapter = WKTAdapter
@cached_property
def is_mysql_5_6(self):
return self.connection.mysql_version < (5, 7, 6)
@cached_property @cached_property
def select(self): def select(self):
return self.geom_func_prefix + 'AsBinary(%s)' return self.geom_func_prefix + 'AsBinary(%s)'
@ -33,7 +29,9 @@ class MySQLOperations(BaseSpatialOperations, DatabaseOperations):
@cached_property @cached_property
def gis_operators(self): def gis_operators(self):
MBREquals = 'MBREqual' if self.is_mysql_5_6 else 'MBREquals' MBREquals = 'MBREqual' if (
self.connection.mysql_is_mariadb or self.connection.mysql_version < (5, 7, 6)
) else 'MBREquals'
return { return {
'bbcontains': SpatialOperator(func='MBRContains'), # For consistency w/PostGIS API 'bbcontains': SpatialOperator(func='MBRContains'), # For consistency w/PostGIS API
'bboverlaps': SpatialOperator(func='MBROverlaps'), # ... 'bboverlaps': SpatialOperator(func='MBROverlaps'), # ...
@ -62,7 +60,11 @@ class MySQLOperations(BaseSpatialOperations, DatabaseOperations):
'MemSize', 'Perimeter', 'PointOnSurface', 'Reverse', 'Scale', 'MemSize', 'Perimeter', 'PointOnSurface', 'Reverse', 'Scale',
'SnapToGrid', 'Transform', 'Translate', 'SnapToGrid', 'Transform', 'Translate',
} }
if self.connection.mysql_version < (5, 7, 5): if self.connection.mysql_is_mariadb:
unsupported.update({'GeoHash', 'IsValid'})
if self.connection.mysql_version < (10, 2, 4):
unsupported.add('AsGeoJSON')
elif self.connection.mysql_version < (5, 7, 5):
unsupported.update({'AsGeoJSON', 'GeoHash', 'IsValid'}) unsupported.update({'AsGeoJSON', 'GeoHash', 'IsValid'})
return unsupported return unsupported

View File

@ -141,6 +141,8 @@ class OGRInspectTest(TestCase):
else: else:
self.assertIn(' f_decimal = models.DecimalField(max_digits=0, decimal_places=0)', model_def) self.assertIn(' f_decimal = models.DecimalField(max_digits=0, decimal_places=0)', model_def)
self.assertIn(' f_int = models.IntegerField()', model_def) self.assertIn(' f_int = models.IntegerField()', model_def)
if connection.vendor != 'mysql' or not connection.mysql_is_mariadb:
# Probably a bug between GDAL and MariaDB on time fields.
self.assertIn(' f_datetime = models.DateTimeField()', model_def) self.assertIn(' f_datetime = models.DateTimeField()', model_def)
self.assertIn(' f_time = models.TimeField()', model_def) self.assertIn(' f_time = models.TimeField()', model_def)
if connection.vendor == 'sqlite': if connection.vendor == 'sqlite':