PageRenderTime 39ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://code.google.com/p/mango-py/
Python | 42 lines | 33 code | 7 blank | 2 comment | 2 complexity | 1cfe54127da1988e0dfbe81d5b06ad41 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. from django.db.backends.oracle.creation import DatabaseCreation
  2. from django.db.backends.util import truncate_name
  3. class OracleCreation(DatabaseCreation):
  4. def sql_indexes_for_field(self, model, f, style):
  5. "Return any spatial index creation SQL for the field."
  6. from django.contrib.gis.db.models.fields import GeometryField
  7. output = super(OracleCreation, self).sql_indexes_for_field(model, f, style)
  8. if isinstance(f, GeometryField):
  9. gqn = self.connection.ops.geo_quote_name
  10. qn = self.connection.ops.quote_name
  11. db_table = model._meta.db_table
  12. output.append(style.SQL_KEYWORD('INSERT INTO ') +
  13. style.SQL_TABLE('USER_SDO_GEOM_METADATA') +
  14. ' (%s, %s, %s, %s)\n ' % tuple(map(qn, ['TABLE_NAME', 'COLUMN_NAME', 'DIMINFO', 'SRID'])) +
  15. style.SQL_KEYWORD(' VALUES ') + '(\n ' +
  16. style.SQL_TABLE(gqn(db_table)) + ',\n ' +
  17. style.SQL_FIELD(gqn(f.column)) + ',\n ' +
  18. style.SQL_KEYWORD("MDSYS.SDO_DIM_ARRAY") + '(\n ' +
  19. style.SQL_KEYWORD("MDSYS.SDO_DIM_ELEMENT") +
  20. ("('LONG', %s, %s, %s),\n " % (f._extent[0], f._extent[2], f._tolerance)) +
  21. style.SQL_KEYWORD("MDSYS.SDO_DIM_ELEMENT") +
  22. ("('LAT', %s, %s, %s)\n ),\n" % (f._extent[1], f._extent[3], f._tolerance)) +
  23. ' %s\n );' % f.srid)
  24. if f.spatial_index:
  25. # Getting the index name, Oracle doesn't allow object
  26. # names > 30 characters.
  27. idx_name = truncate_name('%s_%s_id' % (db_table, f.column), 30)
  28. output.append(style.SQL_KEYWORD('CREATE INDEX ') +
  29. style.SQL_TABLE(qn(idx_name)) +
  30. style.SQL_KEYWORD(' ON ') +
  31. style.SQL_TABLE(qn(db_table)) + '(' +
  32. style.SQL_FIELD(qn(f.column)) + ') ' +
  33. style.SQL_KEYWORD('INDEXTYPE IS ') +
  34. style.SQL_TABLE('MDSYS.SPATIAL_INDEX') + ';')
  35. return output