Refs #30123 -- Changed second arg of DatabaseIntrospection.get_geometry_type() to the row description.

This commit is contained in:
Nick Pope 2019-01-19 14:00:24 +00:00 committed by Tim Graham
parent 2de7eb6f4d
commit 327bbaae24
6 changed files with 14 additions and 14 deletions

View File

@ -10,7 +10,7 @@ class MySQLIntrospection(DatabaseIntrospection):
data_types_reverse = DatabaseIntrospection.data_types_reverse.copy()
data_types_reverse[FIELD_TYPE.GEOMETRY] = 'GeometryField'
def get_geometry_type(self, table_name, geo_col):
def get_geometry_type(self, table_name, description):
with self.connection.cursor() as cursor:
# In order to get the specific geometry type of the field,
# we introspect on the table definition using `DESCRIBE`.
@ -19,7 +19,7 @@ class MySQLIntrospection(DatabaseIntrospection):
# Increment over description info until we get to the geometry
# column.
for column, typ, null, key, default, extra in cursor.fetchall():
if column == geo_col:
if column == description.name:
# Using OGRGeomType to convert from OGC name to Django field.
# MySQL does not support 3D or SRIDs, so the field params
# are empty.

View File

@ -10,20 +10,20 @@ class OracleIntrospection(DatabaseIntrospection):
data_types_reverse = DatabaseIntrospection.data_types_reverse.copy()
data_types_reverse[cx_Oracle.OBJECT] = 'GeometryField'
def get_geometry_type(self, table_name, geo_col):
def get_geometry_type(self, table_name, description):
with self.connection.cursor() as cursor:
# Querying USER_SDO_GEOM_METADATA to get the SRID and dimension information.
try:
cursor.execute(
'SELECT "DIMINFO", "SRID" FROM "USER_SDO_GEOM_METADATA" '
'WHERE "TABLE_NAME"=%s AND "COLUMN_NAME"=%s',
(table_name.upper(), geo_col.upper())
(table_name.upper(), description.name.upper())
)
row = cursor.fetchone()
except Exception as exc:
raise Exception(
'Could not find entry in USER_SDO_GEOM_METADATA '
'corresponding to "%s"."%s"' % (table_name, geo_col)
'corresponding to "%s"."%s"' % (table_name, description.name)
) from exc
# TODO: Research way to find a more specific geometry field type for

View File

@ -53,7 +53,7 @@ class PostGISIntrospection(DatabaseIntrospection):
self.data_types_reverse.update(self.postgis_types_reverse)
return super().get_field_type(data_type, description)
def get_geometry_type(self, table_name, geo_col):
def get_geometry_type(self, table_name, description):
"""
The geometry type OID used by PostGIS does not indicate the particular
type of field that a geometry column is (e.g., whether it's a
@ -67,11 +67,11 @@ class PostGISIntrospection(DatabaseIntrospection):
UNION ALL
SELECT * FROM geography_columns
) AS t WHERE t.f_table_name = %s AND t.f_geometry_column = %s
""", (table_name, geo_col))
""", (table_name, description.name))
row = cursor.fetchone()
if not row:
raise Exception('Could not find a geometry or geography column for "%s"."%s"' %
(table_name, geo_col))
(table_name, description.name))
dim, srid, field_type = row
# OGRGeomType does not require GDAL and makes it easy to convert
# from OGC geom type name to Django field.

View File

@ -24,17 +24,17 @@ class GeoFlexibleFieldLookupDict(FlexibleFieldLookupDict):
class SpatiaLiteIntrospection(DatabaseIntrospection):
data_types_reverse = GeoFlexibleFieldLookupDict()
def get_geometry_type(self, table_name, geo_col):
def get_geometry_type(self, table_name, description):
with self.connection.cursor() as cursor:
# Querying the `geometry_columns` table to get additional metadata.
cursor.execute('SELECT coord_dimension, srid, geometry_type '
'FROM geometry_columns '
'WHERE f_table_name=%s AND f_geometry_column=%s',
(table_name, geo_col))
(table_name, description.name))
row = cursor.fetchone()
if not row:
raise Exception('Could not find a geometry column for "%s"."%s"' %
(table_name, geo_col))
(table_name, description.name))
# OGRGeomType does not require GDAL and makes it easy to convert
# from OGC geom type name to Django field.

View File

@ -9,9 +9,8 @@ class Command(InspectDBCommand):
def get_field_type(self, connection, table_name, row):
field_type, field_params, field_notes = super().get_field_type(connection, table_name, row)
if field_type == 'GeometryField':
geo_col = row[0]
# Getting a more specific field type and any additional parameters
# from the `get_geometry_type` routine for the spatial backend.
field_type, geo_params = connection.introspection.get_geometry_type(table_name, geo_col)
field_type, geo_params = connection.introspection.get_geometry_type(table_name, row)
field_params.update(geo_params)
return field_type, field_params, field_notes

View File

@ -208,7 +208,8 @@ Database backend API
This section describes changes that may be needed in third-party database
backends.
* ...
* The second argument of ``DatabaseIntrospection.get_geometry_type()`` is now
the row description instead of the column name.
Miscellaneous
-------------