Ticket #10888: orcl_null_v1.diff

File orcl_null_v1.diff, 2.3 KB (added by jbronn, 16 years ago)
  • django/contrib/gis/db/models/sql/subqueries.py

     
     1from django.contrib.gis.db.backend import SpatialBackend
     2from django.db.models.query import insert_query
     3
     4if SpatialBackend.oracle:
     5    from django.db import connection
     6    from django.db.models.sql.subqueries import InsertQuery
     7
     8    class GeoInsertQuery(InsertQuery):
     9        def insert_values(self, insert_values, raw_values=False):
     10            placeholders, values = [], []
     11            for field, val in insert_values:
     12                if hasattr(field, 'get_placeholder'):
     13                    if hasattr(field, 'geom_type') and val is None:
     14                        placeholders.append('NULL')
     15                    else:
     16                        placeholders.append(field.get_placeholder(val))
     17                        values.append(val)
     18                else:
     19                    placeholders.append('%s')
     20                    values.append(val)
     21                self.columns.append(field.column)
     22
     23            if raw_values:
     24                self.values.extend(values)
     25            else:
     26                self.params += tuple(values)
     27                self.values.extend(placeholders)
     28
     29    def insert_query(model, values, return_id=False, raw_values=False):
     30        query = GeoInsertQuery(model, connection)
     31        query.insert_values(values, raw_values)
     32        return query.execute_sql(return_id)
     33   
  • django/contrib/gis/db/models/manager.py

     
    11from django.db.models.manager import Manager
    22from django.contrib.gis.db.models.query import GeoQuerySet
     3from django.contrib.gis.db.models.sql.subqueries import insert_query
    34
    45class GeoManager(Manager):
    56    "Overrides Manager to return Geographic QuerySets."
     
    8687
    8788    def unionagg(self, *args, **kwargs):
    8889        return self.get_query_set().unionagg(*args, **kwargs)
     90
     91    def _insert(self, values, **kwargs):
     92        return insert_query(self.model, values, **kwargs)
Back to Top