Debian Codegraph @

django/contrib/gis/db/backends/oracle/introspection.py

raw
1 from django.db.backends.oracle.introspection import DatabaseIntrospection
2 from django.db.backends.oracle.oracledb_any import oracledb
3 from django.utils.functional import cached_property
4
5
6 class OracleIntrospection(DatabaseIntrospection):
7 # Associating any OBJECTVAR instances with GeometryField. This won't work
8 # right on Oracle objects that aren't MDSYS.SDO_GEOMETRY, but it is the
9 # only object type supported within Django anyways.
10 @cached_property
11 def data_types_reverse(self):
12 return {
13 **super().data_types_reverse,
14 oracledb.DB_TYPE_OBJECT: "GeometryField",
15 }
16
17 def get_geometry_type(self, table_name, description):
18 with self.connection.cursor() as cursor:
19 # Querying USER_SDO_GEOM_METADATA to get the SRID and dimension information.
20 try:
21 cursor.execute(
22 'SELECT "DIMINFO", "SRID" FROM "USER_SDO_GEOM_METADATA" '
23 'WHERE "TABLE_NAME"=%s AND "COLUMN_NAME"=%s',
24 (table_name.upper(), description.name.upper()),
25 )
26 row = cursor.fetchone()
27 except Exception as exc:
28 raise Exception(
29 "Could not find entry in USER_SDO_GEOM_METADATA "
30 'corresponding to "%s"."%s"' % (table_name, description.name)
31 ) from exc
32
33 # TODO: Research way to find a more specific geometry field type for
34 # the column's contents.
35 field_type = "GeometryField"
36
37 # Getting the field parameters.
38 field_params = {}
39 dim, srid = row
40 if srid != 4326:
41 field_params["srid"] = srid
42 # Size of object array (SDO_DIM_ARRAY) is number of dimensions.
43 dim = dim.size()
44 if dim != 2:
45 field_params["dim"] = dim
46 return field_type, field_params