summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Pope <nick.pope@flightdataservices.com>2019-01-19 14:00:24 +0000
committerTim Graham <timograham@gmail.com>2019-01-23 13:18:03 -0500
commit327bbaae24805937ebdb9dc80e2a1b75439d9044 (patch)
tree09dbfd8074ec57d752e35ac53c0f40d938303cc8
parent2de7eb6f4d5a20cec98e4d2eefc276ee38d149ad (diff)
Refs #30123 -- Changed second arg of DatabaseIntrospection.get_geometry_type() to the row description.
-rw-r--r--django/contrib/gis/db/backends/mysql/introspection.py4
-rw-r--r--django/contrib/gis/db/backends/oracle/introspection.py6
-rw-r--r--django/contrib/gis/db/backends/postgis/introspection.py6
-rw-r--r--django/contrib/gis/db/backends/spatialite/introspection.py6
-rw-r--r--django/contrib/gis/management/commands/inspectdb.py3
-rw-r--r--docs/releases/3.0.txt3
6 files changed, 14 insertions, 14 deletions
diff --git a/django/contrib/gis/db/backends/mysql/introspection.py b/django/contrib/gis/db/backends/mysql/introspection.py
index 9e19522267..3dc4ae6488 100644
--- a/django/contrib/gis/db/backends/mysql/introspection.py
+++ b/django/contrib/gis/db/backends/mysql/introspection.py
@@ -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.
diff --git a/django/contrib/gis/db/backends/oracle/introspection.py b/django/contrib/gis/db/backends/oracle/introspection.py
index 7f4f886a34..5e71c84fdd 100644
--- a/django/contrib/gis/db/backends/oracle/introspection.py
+++ b/django/contrib/gis/db/backends/oracle/introspection.py
@@ -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
diff --git a/django/contrib/gis/db/backends/postgis/introspection.py b/django/contrib/gis/db/backends/postgis/introspection.py
index 82455d4c18..66c5bb5d42 100644
--- a/django/contrib/gis/db/backends/postgis/introspection.py
+++ b/django/contrib/gis/db/backends/postgis/introspection.py
@@ -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.
diff --git a/django/contrib/gis/db/backends/spatialite/introspection.py b/django/contrib/gis/db/backends/spatialite/introspection.py
index 967448621d..ccb9f0a1af 100644
--- a/django/contrib/gis/db/backends/spatialite/introspection.py
+++ b/django/contrib/gis/db/backends/spatialite/introspection.py
@@ -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.
diff --git a/django/contrib/gis/management/commands/inspectdb.py b/django/contrib/gis/management/commands/inspectdb.py
index af70d6015a..8c6f62932a 100644
--- a/django/contrib/gis/management/commands/inspectdb.py
+++ b/django/contrib/gis/management/commands/inspectdb.py
@@ -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
diff --git a/docs/releases/3.0.txt b/docs/releases/3.0.txt
index a76f174208..d7643cf3b6 100644
--- a/docs/releases/3.0.txt
+++ b/docs/releases/3.0.txt
@@ -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
-------------