1
from django.contrib.gis.db.backend import SpatialBackend
2
from django.db.models.query import insert_query
4
if SpatialBackend.oracle:
5
from django.db import connection
6
from django.db.models.sql.subqueries import InsertQuery
8
class OracleGeoInsertQuery(InsertQuery):
9
def insert_values(self, insert_values, raw_values=False):
11
This routine is overloaded from InsertQuery so that no parameter is
12
passed into cx_Oracle for NULL geometries. The reason is that
13
cx_Oracle has no way to bind Oracle object values (like
16
placeholders, values = [], []
17
for field, val in insert_values:
18
if hasattr(field, 'get_placeholder'):
19
ph = field.get_placeholder(val)
23
placeholders.append(ph)
24
self.columns.append(field.column)
26
# If 'NULL' for the placeholder, omit appending None
27
# to the values list (which is used for db params).
31
self.values.extend(values)
33
self.params += tuple(values)
34
self.values.extend(placeholders)
36
def insert_query(model, values, return_id=False, raw_values=False):
37
query = OracleGeoInsertQuery(model, connection)
38
query.insert_values(values, raw_values)
39
return query.execute_sql(return_id)