~ubuntu-branches/ubuntu/quantal/python-django/quantal-security

« back to all changes in this revision

Viewing changes to django/contrib/gis/db/models/sql/subqueries.py

  • Committer: Bazaar Package Importer
  • Author(s): Chris Lamb
  • Date: 2010-05-21 07:52:55 UTC
  • mfrom: (1.3.6 upstream)
  • mto: This revision was merged to the branch mainline in revision 28.
  • Revision ID: james.westby@ubuntu.com-20100521075255-ii78v1dyfmyu3uzx
Tags: upstream-1.2
ImportĀ upstreamĀ versionĀ 1.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
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)