mirror of
				https://github.com/django/django.git
				synced 2025-10-30 17:16:10 +00:00 
			
		
		
		
	[1.10.x] Refs #26134 -- Updated deprecated MySQL GIS function names.
Backport of 92f88206d0 from master
			
			
This commit is contained in:
		| @@ -14,46 +14,62 @@ class MySQLOperations(BaseSpatialOperations, DatabaseOperations): | |||||||
|  |  | ||||||
|     Adapter = WKTAdapter |     Adapter = WKTAdapter | ||||||
|  |  | ||||||
|  |     @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) | ||||||
|  |  | ||||||
|     @cached_property |     @cached_property | ||||||
|     def select(self): |     def select(self): | ||||||
|         if self.connection.mysql_version < (5, 6, 0): |         if self.is_mysql_5_5: | ||||||
|             return 'AsText(%s)' |             return 'AsText(%s)' | ||||||
|         return 'ST_AsText(%s)' |         return 'ST_AsText(%s)' | ||||||
|  |  | ||||||
|     @cached_property |     @cached_property | ||||||
|     def from_wkb(self): |     def from_wkb(self): | ||||||
|         if self.connection.mysql_version < (5, 6, 0): |         if self.is_mysql_5_5: | ||||||
|             return 'GeomFromWKB' |             return 'GeomFromWKB' | ||||||
|         return 'ST_GeomFromWKB' |         return 'ST_GeomFromWKB' | ||||||
|  |  | ||||||
|     @cached_property |     @cached_property | ||||||
|     def from_text(self): |     def from_text(self): | ||||||
|         if self.connection.mysql_version < (5, 6, 0): |         if self.is_mysql_5_5: | ||||||
|             return 'GeomFromText' |             return 'GeomFromText' | ||||||
|         return 'ST_GeomFromText' |         return 'ST_GeomFromText' | ||||||
|  |  | ||||||
|     gis_operators = { |     @cached_property | ||||||
|         'bbcontains': SpatialOperator(func='MBRContains'),  # For consistency w/PostGIS API |     def gis_operators(self): | ||||||
|         'bboverlaps': SpatialOperator(func='MBROverlaps'),  # .. .. |         MBREquals = 'MBREqual' if self.is_mysql_5_6 else 'MBREquals' | ||||||
|         'contained': SpatialOperator(func='MBRWithin'),    # .. .. |         return { | ||||||
|         'contains': SpatialOperator(func='MBRContains'), |             'bbcontains': SpatialOperator(func='MBRContains'),  # For consistency w/PostGIS API | ||||||
|         'disjoint': SpatialOperator(func='MBRDisjoint'), |             'bboverlaps': SpatialOperator(func='MBROverlaps'),  # ... | ||||||
|         'equals': SpatialOperator(func='MBREqual'), |             'contained': SpatialOperator(func='MBRWithin'),  # ... | ||||||
|         'exact': SpatialOperator(func='MBREqual'), |             'contains': SpatialOperator(func='MBRContains'), | ||||||
|         'intersects': SpatialOperator(func='MBRIntersects'), |             'disjoint': SpatialOperator(func='MBRDisjoint'), | ||||||
|         'overlaps': SpatialOperator(func='MBROverlaps'), |             'equals': SpatialOperator(func=MBREquals), | ||||||
|         'same_as': SpatialOperator(func='MBREqual'), |             'exact': SpatialOperator(func=MBREquals), | ||||||
|         'touches': SpatialOperator(func='MBRTouches'), |             'intersects': SpatialOperator(func='MBRIntersects'), | ||||||
|         'within': SpatialOperator(func='MBRWithin'), |             'overlaps': SpatialOperator(func='MBROverlaps'), | ||||||
|     } |             'same_as': SpatialOperator(func=MBREquals), | ||||||
|  |             'touches': SpatialOperator(func='MBRTouches'), | ||||||
|  |             'within': SpatialOperator(func='MBRWithin'), | ||||||
|  |         } | ||||||
|  |  | ||||||
|     @cached_property |     @cached_property | ||||||
|     def function_names(self): |     def function_names(self): | ||||||
|         return { |         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', |             'Difference': 'ST_Difference', | ||||||
|             'Distance': 'ST_Distance', |             'Distance': 'ST_Distance', | ||||||
|  |             'Envelope': 'Envelope' if self.is_mysql_5_5 else 'ST_Envelope', | ||||||
|             'Intersection': 'ST_Intersection', |             'Intersection': 'ST_Intersection', | ||||||
|             'Length': 'GLength' if self.connection.mysql_version < (5, 6, 0) else 'ST_Length', |             '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', |             'SymDifference': 'ST_SymDifference', | ||||||
|             'Union': 'ST_Union', |             'Union': 'ST_Union', | ||||||
|         } |         } | ||||||
| @@ -71,7 +87,7 @@ class MySQLOperations(BaseSpatialOperations, DatabaseOperations): | |||||||
|             'Perimeter', 'PointOnSurface', 'Reverse', 'Scale', 'SnapToGrid', |             'Perimeter', 'PointOnSurface', 'Reverse', 'Scale', 'SnapToGrid', | ||||||
|             'Transform', 'Translate', |             'Transform', 'Translate', | ||||||
|         } |         } | ||||||
|         if self.connection.mysql_version < (5, 6, 1): |         if self.is_mysql_5_5: | ||||||
|             unsupported.update({'Difference', 'Distance', 'Intersection', 'SymDifference', 'Union'}) |             unsupported.update({'Difference', 'Distance', 'Intersection', 'SymDifference', 'Union'}) | ||||||
|         return unsupported |         return unsupported | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user