/django/contrib/gis/db/backends/mysql/introspection.py
Python | 32 lines | 19 code | 4 blank | 9 comment | 3 complexity | 457976f28de1530b39450fdb445bed4f MD5 | raw file
Possible License(s): BSD-3-Clause
1from MySQLdb.constants import FIELD_TYPE 2 3from django.contrib.gis.gdal import OGRGeomType 4from django.db.backends.mysql.introspection import DatabaseIntrospection 5 6class MySQLIntrospection(DatabaseIntrospection): 7 # Updating the data_types_reverse dictionary with the appropriate 8 # type for Geometry fields. 9 data_types_reverse = DatabaseIntrospection.data_types_reverse.copy() 10 data_types_reverse[FIELD_TYPE.GEOMETRY] = 'GeometryField' 11 12 def get_geometry_type(self, table_name, geo_col): 13 cursor = self.connection.cursor() 14 try: 15 # In order to get the specific geometry type of the field, 16 # we introspect on the table definition using `DESCRIBE`. 17 cursor.execute('DESCRIBE %s' % 18 self.connection.ops.quote_name(table_name)) 19 # Increment over description info until we get to the geometry 20 # column. 21 for column, typ, null, key, default, extra in cursor.fetchall(): 22 if column == geo_col: 23 # Using OGRGeomType to convert from OGC name to Django field. 24 # MySQL does not support 3D or SRIDs, so the field params 25 # are empty. 26 field_type = OGRGeomType(typ).django 27 field_params = {} 28 break 29 finally: 30 cursor.close() 31 32 return field_type, field_params