|
1 from django.contrib.gis.db.models.sql.compiler import GeoSQLCompiler as BaseGeoSQLCompiler |
|
2 from django.db.backends.oracle import compiler |
|
3 |
|
4 SQLCompiler = compiler.SQLCompiler |
|
5 |
|
6 class GeoSQLCompiler(BaseGeoSQLCompiler, SQLCompiler): |
|
7 pass |
|
8 |
|
9 class SQLInsertCompiler(compiler.SQLInsertCompiler, GeoSQLCompiler): |
|
10 def placeholder(self, field, val): |
|
11 if field is None: |
|
12 # A field value of None means the value is raw. |
|
13 return val |
|
14 elif hasattr(field, 'get_placeholder'): |
|
15 # Some fields (e.g. geo fields) need special munging before |
|
16 # they can be inserted. |
|
17 ph = field.get_placeholder(val, self.connection) |
|
18 if ph == 'NULL': |
|
19 # If the placeholder returned is 'NULL', then we need to |
|
20 # to remove None from the Query parameters. Specifically, |
|
21 # cx_Oracle will assume a CHAR type when a placeholder ('%s') |
|
22 # is used for columns of MDSYS.SDO_GEOMETRY. Thus, we use |
|
23 # 'NULL' for the value, and remove None from the query params. |
|
24 # See also #10888. |
|
25 param_idx = self.query.columns.index(field.column) |
|
26 params = list(self.query.params) |
|
27 params.pop(param_idx) |
|
28 self.query.params = tuple(params) |
|
29 return ph |
|
30 else: |
|
31 # Return the common case for the placeholder |
|
32 return '%s' |
|
33 |
|
34 class SQLDeleteCompiler(compiler.SQLDeleteCompiler, GeoSQLCompiler): |
|
35 pass |
|
36 |
|
37 class SQLUpdateCompiler(compiler.SQLUpdateCompiler, GeoSQLCompiler): |
|
38 pass |
|
39 |
|
40 class SQLAggregateCompiler(compiler.SQLAggregateCompiler, GeoSQLCompiler): |
|
41 pass |
|
42 |
|
43 class SQLDateCompiler(compiler.SQLDateCompiler, GeoSQLCompiler): |
|
44 pass |