|
0
|
1 |
from django.contrib.gis.db.backend import SpatialBackend |
|
|
2 |
from django.db.models.query import insert_query |
|
|
3 |
|
|
|
4 |
if SpatialBackend.oracle: |
|
|
5 |
from django.db import connection |
|
|
6 |
from django.db.models.sql.subqueries import InsertQuery |
|
|
7 |
|
|
|
8 |
class OracleGeoInsertQuery(InsertQuery): |
|
|
9 |
def insert_values(self, insert_values, raw_values=False): |
|
|
10 |
""" |
|
|
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 |
|
|
14 |
MDSYS.SDO_GEOMETRY). |
|
|
15 |
""" |
|
|
16 |
placeholders, values = [], [] |
|
|
17 |
for field, val in insert_values: |
|
|
18 |
if hasattr(field, 'get_placeholder'): |
|
|
19 |
ph = field.get_placeholder(val) |
|
|
20 |
else: |
|
|
21 |
ph = '%s' |
|
|
22 |
|
|
|
23 |
placeholders.append(ph) |
|
|
24 |
self.columns.append(field.column) |
|
|
25 |
|
|
|
26 |
# If 'NULL' for the placeholder, omit appending None |
|
|
27 |
# to the values list (which is used for db params). |
|
|
28 |
if not ph == 'NULL': |
|
|
29 |
values.append(val) |
|
|
30 |
if raw_values: |
|
|
31 |
self.values.extend(values) |
|
|
32 |
else: |
|
|
33 |
self.params += tuple(values) |
|
|
34 |
self.values.extend(placeholders) |
|
|
35 |
|
|
|
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) |