PageRenderTime 172ms CodeModel.GetById 151ms app.highlight 3ms RepoModel.GetById 17ms app.codeStats 0ms

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

https://code.google.com/p/mango-py/
Python | 44 lines | 27 code | 7 blank | 10 comment | 2 complexity | 3ea27f66ed9fb3228f31105bba39faf1 MD5 | raw file
 1from django.contrib.gis.db.models.sql.compiler import GeoSQLCompiler as BaseGeoSQLCompiler
 2from django.db.backends.oracle import compiler
 3
 4SQLCompiler = compiler.SQLCompiler
 5
 6class GeoSQLCompiler(BaseGeoSQLCompiler, SQLCompiler):
 7    pass
 8
 9class 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
34class SQLDeleteCompiler(compiler.SQLDeleteCompiler, GeoSQLCompiler):
35    pass
36
37class SQLUpdateCompiler(compiler.SQLUpdateCompiler, GeoSQLCompiler):
38    pass
39
40class SQLAggregateCompiler(compiler.SQLAggregateCompiler, GeoSQLCompiler):
41    pass
42
43class SQLDateCompiler(compiler.SQLDateCompiler, GeoSQLCompiler):
44    pass