From c47364ef0c368c9a0257dba68534d8781019cee4 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Fri, 29 Jan 2016 23:25:15 +0100 Subject: [PATCH] Fixed #26134 -- Used new OpenGIS names for recent MySQL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Thanks FrantiĊĦek Malina for the report. --- .../gis/db/backends/mysql/operations.py | 39 +++++++++++++------ 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/django/contrib/gis/db/backends/mysql/operations.py b/django/contrib/gis/db/backends/mysql/operations.py index c31504c40e4..3aedc240408 100644 --- a/django/contrib/gis/db/backends/mysql/operations.py +++ b/django/contrib/gis/db/backends/mysql/operations.py @@ -11,12 +11,27 @@ class MySQLOperations(BaseSpatialOperations, DatabaseOperations): mysql = True name = 'mysql' - select = 'AsText(%s)' - from_wkb = 'GeomFromWKB' - from_text = 'GeomFromText' Adapter = WKTAdapter + @cached_property + def select(self): + if self.connection.mysql_version < (5, 6, 0): + return 'AsText(%s)' + return 'ST_AsText(%s)' + + @cached_property + def from_wkb(self): + if self.connection.mysql_version < (5, 6, 0): + return 'GeomFromWKB' + return 'ST_GeomFromWKB' + + @cached_property + def from_text(self): + if self.connection.mysql_version < (5, 6, 0): + return 'GeomFromText' + return 'ST_GeomFromText' + gis_operators = { 'bbcontains': SpatialOperator(func='MBRContains'), # For consistency w/PostGIS API 'bboverlaps': SpatialOperator(func='MBROverlaps'), # .. .. @@ -32,14 +47,16 @@ class MySQLOperations(BaseSpatialOperations, DatabaseOperations): 'within': SpatialOperator(func='MBRWithin'), } - function_names = { - 'Difference': 'ST_Difference', - 'Distance': 'ST_Distance', - 'Intersection': 'ST_Intersection', - 'Length': 'GLength', - 'SymDifference': 'ST_SymDifference', - 'Union': 'ST_Union', - } + @cached_property + def function_names(self): + return { + 'Difference': 'ST_Difference', + 'Distance': 'ST_Distance', + 'Intersection': 'ST_Intersection', + 'Length': 'GLength' if self.connection.mysql_version < (5, 6, 0) else 'ST_Length', + 'SymDifference': 'ST_SymDifference', + 'Union': 'ST_Union', + } disallowed_aggregates = ( aggregates.Collect, aggregates.Extent, aggregates.Extent3D,