~ubuntu-branches/ubuntu/oneiric/python-django/oneiric-201108291626

« back to all changes in this revision

Viewing changes to django/contrib/gis/db/backends/mysql/introspection.py

  • Committer: Bazaar Package Importer
  • Author(s): Chris Lamb
  • Date: 2010-05-21 07:52:55 UTC
  • mfrom: (1.1.10 upstream) (4.4.7 sid)
  • Revision ID: james.westby@ubuntu.com-20100521075255-i1zpeyc0k8512pd7
Tags: 1.2-1
New upstream stable release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from MySQLdb.constants import FIELD_TYPE
 
2
 
 
3
from django.contrib.gis.gdal import OGRGeomType
 
4
from django.db.backends.mysql.introspection import DatabaseIntrospection
 
5
 
 
6
class 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