PageRenderTime 33ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://code.google.com/p/mango-py/
Python | 39 lines | 26 code | 5 blank | 8 comment | 6 complexity | 7410a66e129bcff7294a50a4495beed0 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. import cx_Oracle
  2. from django.db.backends.oracle.introspection import DatabaseIntrospection
  3. class OracleIntrospection(DatabaseIntrospection):
  4. # Associating any OBJECTVAR instances with GeometryField. Of course,
  5. # this won't work right on Oracle objects that aren't MDSYS.SDO_GEOMETRY,
  6. # but it is the only object type supported within Django anyways.
  7. data_types_reverse = DatabaseIntrospection.data_types_reverse.copy()
  8. data_types_reverse[cx_Oracle.OBJECT] = 'GeometryField'
  9. def get_geometry_type(self, table_name, geo_col):
  10. cursor = self.connection.cursor()
  11. try:
  12. # Querying USER_SDO_GEOM_METADATA to get the SRID and dimension information.
  13. try:
  14. cursor.execute('SELECT "DIMINFO", "SRID" FROM "USER_SDO_GEOM_METADATA" WHERE "TABLE_NAME"=%s AND "COLUMN_NAME"=%s',
  15. (table_name.upper(), geo_col.upper()))
  16. row = cursor.fetchone()
  17. except Exception, msg:
  18. raise Exception('Could not find entry in USER_SDO_GEOM_METADATA corresponding to "%s"."%s"\n'
  19. 'Error message: %s.' % (table_name, geo_col, msg))
  20. # TODO: Research way to find a more specific geometry field type for
  21. # the column's contents.
  22. field_type = 'GeometryField'
  23. # Getting the field parameters.
  24. field_params = {}
  25. dim, srid = row
  26. if srid != 4326:
  27. field_params['srid'] = srid
  28. # Length of object array ( SDO_DIM_ARRAY ) is number of dimensions.
  29. dim = len(dim)
  30. if dim != 2:
  31. field_params['dim'] = dim
  32. finally:
  33. cursor.close()
  34. return field_type, field_params