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