summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Fedoseev <fedoseev.sergey@gmail.com>2016-10-24 21:12:47 +0600
committerTim Graham <timograham@gmail.com>2016-10-24 11:12:47 -0400
commit7d51e406bdab2bb285195eeac8399331d45ab065 (patch)
treeea5d1cbad3c93a7073129e4789d3bd9d879ea2bf
parent6b5106b1ceec03d945c1104b21feed3e25470fe0 (diff)
Added MySQLOperations.geom_func_prefix to simplify.
-rw-r--r--django/contrib/gis/db/backends/mysql/operations.py30
1 files changed, 8 insertions, 22 deletions
diff --git a/django/contrib/gis/db/backends/mysql/operations.py b/django/contrib/gis/db/backends/mysql/operations.py
index ce91428d53..7d8adbf158 100644
--- a/django/contrib/gis/db/backends/mysql/operations.py
+++ b/django/contrib/gis/db/backends/mysql/operations.py
@@ -15,6 +15,10 @@ class MySQLOperations(BaseSpatialOperations, DatabaseOperations):
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)
@@ -28,21 +32,15 @@ class MySQLOperations(BaseSpatialOperations, DatabaseOperations):
@cached_property
def select(self):
- if self.is_mysql_5_5:
- return 'AsText(%s)'
- return 'ST_AsText(%s)'
+ return self.geom_func_prefix + 'AsText(%s)'
@cached_property
def from_wkb(self):
- if self.is_mysql_5_5:
- return 'GeomFromWKB'
- return 'ST_GeomFromWKB'
+ return self.geom_func_prefix + 'GeomFromWKB'
@cached_property
def from_text(self):
- if self.is_mysql_5_5:
- return 'GeomFromText'
- return 'ST_GeomFromText'
+ return self.geom_func_prefix + 'GeomFromText'
@cached_property
def gis_operators(self):
@@ -64,19 +62,7 @@ class MySQLOperations(BaseSpatialOperations, DatabaseOperations):
@cached_property
def function_names(self):
- return {
- 'Area': 'Area' if self.is_mysql_5_5 else 'ST_Area',
- 'Centroid': 'Centroid' if self.is_mysql_5_5 else 'ST_Centroid',
- 'Difference': 'ST_Difference',
- 'Distance': 'ST_Distance',
- 'Envelope': 'Envelope' if self.is_mysql_5_5 else 'ST_Envelope',
- 'Intersection': 'ST_Intersection',
- 'Length': 'GLength' if self.is_mysql_5_5 else 'ST_Length',
- 'NumGeometries': 'NumGeometries' if self.is_mysql_5_5 else 'ST_NumGeometries',
- 'NumPoints': 'NumPoints' if self.is_mysql_5_5 else 'ST_NumPoints',
- 'SymDifference': 'ST_SymDifference',
- 'Union': 'ST_Union',
- }
+ return {'Length': 'GLength'} if self.is_mysql_5_5 else {}
disallowed_aggregates = (
aggregates.Collect, aggregates.Extent, aggregates.Extent3D,