summaryrefslogtreecommitdiff
path: root/django/db
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2009-12-12 02:13:30 +0000
committerAlex Gaynor <alex.gaynor@gmail.com>2009-12-12 02:13:30 +0000
commit049dc42bdea8f524f9d52edd4ddc05ef0048d401 (patch)
tree30186d401cde3159214164995a2ebc88b3114526 /django/db
parentc88113683d6538dbc2f779ff57fd1ea20211abec (diff)
downloaddjango-049dc42bdea8f524f9d52edd4ddc05ef0048d401.tar.gz
[soc2009/multidb] Merged in all of Justin Bronn's GIS work. Multidb should now work fully with GIS. This is backwards incompatible, if you are using GIS, your ENGINE setting should now be django.contrib.gis.db.backends.XXX where XXX is the name of your DB backend. Thanks to Justin for all his work. This also resolves merge conflicts from the previous commit.
git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/multidb@11813 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/db')
-rw-r--r--django/db/backends/__init__.py25
-rw-r--r--django/db/backends/oracle/base.py4
-rw-r--r--django/db/backends/sqlite3/base.py4
-rw-r--r--django/db/models/base.py10
-rw-r--r--django/db/models/fields/related.py23
-rw-r--r--django/db/models/manager.py3
-rw-r--r--django/db/models/query.py10
-rw-r--r--django/db/models/sql/compiler.py2
-rw-r--r--django/db/models/sql/query.py105
-rw-r--r--django/db/models/sql/subqueries.py4
10 files changed, 9 insertions, 181 deletions
diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py
index e64e1d8318..bf3e9db15a 100644
--- a/django/db/backends/__init__.py
+++ b/django/db/backends/__init__.py
@@ -1,20 +1,5 @@
-try:
- # Only exists in Python 2.4+
- from threading import local
-except ImportError:
- # Import copy of _thread_local.py from Python 2.4
- from django.utils._threading_local import local
-try:
- set
-except NameError:
- # Python 2.3 compat
- from sets import Set as set
-
-try:
- import decimal
-except ImportError:
- # Python 2.3 fallback
- from django.utils import _decimal as decimal
+import decimal
+from threading import local
from django.db import DEFAULT_DB_ALIAS
from django.db.backends import util
@@ -286,9 +271,9 @@ class BaseDatabaseOperations(object):
def compiler(self, compiler_name):
"""
- Given the default Query class, returns a custom Query class
- to use for this backend. Returns the Query class unmodified if the
- backend doesn't need a custom Query clsas.
+ Returns the SQLCompiler class corresponding to the given name,
+ in the namespace corresponding to the `compiler_module` attribute
+ on this backend.
"""
if compiler_name not in self._cache:
self._cache[compiler_name] = getattr(
diff --git a/django/db/backends/oracle/base.py b/django/db/backends/oracle/base.py
index dd085008a2..cc85685e5b 100644
--- a/django/db/backends/oracle/base.py
+++ b/django/db/backends/oracle/base.py
@@ -357,11 +357,7 @@ class DatabaseWrapper(BaseDatabaseWrapper):
cursor = None
if not self._valid_connection():
conn_string = convert_unicode(self._connect_string())
-<<<<<<< HEAD:django/db/backends/oracle/base.py
self.connection = Database.connect(conn_string, **self.settings_dict['OPTIONS'])
-=======
- self.connection = Database.connect(conn_string, **self.settings_dict['DATABASE_OPTIONS'])
->>>>>>> master:django/db/backends/oracle/base.py
cursor = FormatStylePlaceholderCursor(self.connection)
# Set oracle date to ansi date format. This only needs to execute
# once when we create a new connection. We also set the Territory
diff --git a/django/db/backends/sqlite3/base.py b/django/db/backends/sqlite3/base.py
index 7f31290fe9..6f78cf2a4a 100644
--- a/django/db/backends/sqlite3/base.py
+++ b/django/db/backends/sqlite3/base.py
@@ -29,10 +29,6 @@ except ImportError, exc:
module = 'either pysqlite2 or sqlite3 modules (tried in that order)'
raise ImproperlyConfigured, "Error loading %s: %s" % (module, exc)
-try:
- import decimal
-except ImportError:
- from django.utils import _decimal as decimal # for Python 2.3
DatabaseError = Database.DatabaseError
IntegrityError = Database.IntegrityError
diff --git a/django/db/models/base.py b/django/db/models/base.py
index 8a6ffd12b3..eb484ea3bc 100644
--- a/django/db/models/base.py
+++ b/django/db/models/base.py
@@ -230,7 +230,6 @@ class ModelBase(type):
signals.class_prepared.send(sender=cls)
-<<<<<<< HEAD:django/db/models/base.py
class ModelState(object):
"""
A class for storing instance state
@@ -238,8 +237,6 @@ class ModelState(object):
def __init__(self, db=None):
self.db = db
-=======
->>>>>>> master:django/db/models/base.py
class Model(object):
__metaclass__ = ModelBase
_deferred = False
@@ -491,11 +488,7 @@ class Model(object):
if pk_set:
# Determine whether a record with the primary key already exists.
if (force_update or (not force_insert and
-<<<<<<< HEAD:django/db/models/base.py
manager.using(using).filter(pk=pk_val).exists())):
-=======
- manager.filter(pk=pk_val).exists())):
->>>>>>> master:django/db/models/base.py
# It does already exist, so do an UPDATE.
if force_update or non_pks:
values = [(f, None, (raw and getattr(self, f.attname) or f.pre_save(self, False))) for f in non_pks]
@@ -534,10 +527,7 @@ class Model(object):
# Store the database on which the object was saved
self._state.db = using
-<<<<<<< HEAD:django/db/models/base.py
# Signal that the save is complete
-=======
->>>>>>> master:django/db/models/base.py
if origin and not meta.auto_created:
signals.post_save.send(sender=origin, instance=self,
created=(not record_exists), raw=raw)
diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py
index e3520965e1..f8ae5b1f4e 100644
--- a/django/db/models/fields/related.py
+++ b/django/db/models/fields/related.py
@@ -474,11 +474,7 @@ def create_many_related_manager(superclass, rel=False):
if not rel.through._meta.auto_created:
opts = through._meta
raise AttributeError, "Cannot use create() on a ManyToManyField which specifies an intermediary model. Use %s.%s's Manager instead." % (opts.app_label, opts.object_name)
-<<<<<<< HEAD:django/db/models/fields/related.py
new_obj = super(ManyRelatedManager, self).using(self.instance._state.db).create(**kwargs)
-=======
- new_obj = super(ManyRelatedManager, self).create(**kwargs)
->>>>>>> master:django/db/models/fields/related.py
self.add(new_obj)
return new_obj
create.alters_data = True
@@ -505,22 +501,15 @@ def create_many_related_manager(superclass, rel=False):
new_ids = set()
for obj in objs:
if isinstance(obj, self.model):
-<<<<<<< HEAD:django/db/models/fields/related.py
if obj._state.db != self.instance._state.db:
raise ValueError('Cannot add "%r": instance is on database "%s", value is is on database "%s"' %
(obj, self.instance._state.db, obj._state.db))
-=======
->>>>>>> master:django/db/models/fields/related.py
new_ids.add(obj.pk)
elif isinstance(obj, Model):
raise TypeError, "'%s' instance expected" % self.model._meta.object_name
else:
new_ids.add(obj)
-<<<<<<< HEAD:django/db/models/fields/related.py
vals = self.through._default_manager.using(self.instance._state.db).values_list(target_field_name, flat=True)
-=======
- vals = self.through._default_manager.values_list(target_field_name, flat=True)
->>>>>>> master:django/db/models/fields/related.py
vals = vals.filter(**{
source_field_name: self._pk_val,
'%s__in' % target_field_name: new_ids,
@@ -529,11 +518,7 @@ def create_many_related_manager(superclass, rel=False):
# Add the ones that aren't there already
for obj_id in (new_ids - vals):
-<<<<<<< HEAD:django/db/models/fields/related.py
self.through._default_manager.using(self.instance._state.db).create(**{
-=======
- self.through._default_manager.create(**{
->>>>>>> master:django/db/models/fields/related.py
'%s_id' % source_field_name: self._pk_val,
'%s_id' % target_field_name: obj_id,
})
@@ -553,22 +538,14 @@ def create_many_related_manager(superclass, rel=False):
else:
old_ids.add(obj)
# Remove the specified objects from the join table
-<<<<<<< HEAD:django/db/models/fields/related.py
self.through._default_manager.using(self.instance._state.db).filter(**{
-=======
- self.through._default_manager.filter(**{
->>>>>>> master:django/db/models/fields/related.py
source_field_name: self._pk_val,
'%s__in' % target_field_name: old_ids
}).delete()
def _clear_items(self, source_field_name):
# source_col_name: the PK colname in join_table for the source object
-<<<<<<< HEAD:django/db/models/fields/related.py
self.through._default_manager.using(self.instance._state.db).filter(**{
-=======
- self.through._default_manager.filter(**{
->>>>>>> master:django/db/models/fields/related.py
source_field_name: self._pk_val
}).delete()
diff --git a/django/db/models/manager.py b/django/db/models/manager.py
index 2bdc615615..d752519f5c 100644
--- a/django/db/models/manager.py
+++ b/django/db/models/manager.py
@@ -172,12 +172,9 @@ class Manager(object):
def only(self, *args, **kwargs):
return self.get_query_set().only(*args, **kwargs)
-<<<<<<< HEAD:django/db/models/manager.py
def using(self, *args, **kwargs):
return self.get_query_set().using(*args, **kwargs)
-=======
->>>>>>> master:django/db/models/manager.py
def exists(self, *args, **kwargs):
return self.get_query_set().exists(*args, **kwargs)
diff --git a/django/db/models/query.py b/django/db/models/query.py
index 05d2514f69..4d92abc92d 100644
--- a/django/db/models/query.py
+++ b/django/db/models/query.py
@@ -3,12 +3,8 @@ The main QuerySet implementation. This provides the public API for the ORM.
"""
from copy import deepcopy
-<<<<<<< HEAD:django/db/models/query.py
from django.db import connections, transaction, IntegrityError, DEFAULT_DB_ALIAS
-=======
-from django.db import connection, transaction, IntegrityError
->>>>>>> master:django/db/models/query.py
from django.db.models.aggregates import Aggregate
from django.db.models.fields import DateField
from django.db.models.query_utils import Q, select_related_descend, CollectedObjects, CyclicDependency, deferred_class_factory
@@ -480,11 +476,7 @@ class QuerySet(object):
def exists(self):
if self._result_cache is None:
-<<<<<<< HEAD:django/db/models/query.py
return self.query.has_results(using=self.db)
-=======
- return self.query.has_results()
->>>>>>> master:django/db/models/query.py
return bool(self._result_cache)
##################################################
@@ -1157,6 +1149,6 @@ def insert_query(model, values, return_id=False, raw_values=False, using=None):
part of the public API.
"""
query = sql.InsertQuery(model)
- query.insert_values(values, raw_values)
compiler = query.get_compiler(using=using)
+ query.insert_values(values, compiler.connection, raw_values)
return compiler.execute_sql(return_id)
diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py
index e0a4208fb4..2b45c5d92e 100644
--- a/django/db/models/sql/compiler.py
+++ b/django/db/models/sql/compiler.py
@@ -755,7 +755,7 @@ class SQLUpdateCompiler(SQLCompiler):
# Getting the placeholder for the field.
if hasattr(field, 'get_placeholder'):
- placeholder = field.get_placeholder(val)
+ placeholder = field.get_placeholder(val, self.connection)
else:
placeholder = '%s'
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
index 3176e7e9df..d1217bf048 100644
--- a/django/db/models/sql/query.py
+++ b/django/db/models/sql/query.py
@@ -22,12 +22,7 @@ from django.db.models.sql.expressions import SQLEvaluator
from django.db.models.sql.where import WhereNode, Constraint, EverythingNode, AND, OR
from django.core.exceptions import FieldError
-<<<<<<< HEAD:django/db/models/sql/query.py
-
__all__ = ['Query']
-=======
-__all__ = ['Query', 'BaseQuery']
->>>>>>> master:django/db/models/sql/query.py
class Query(object):
"""
@@ -341,11 +336,7 @@ class Query(object):
return number
-<<<<<<< HEAD:django/db/models/sql/query.py
def has_results(self, using):
-=======
- def has_results(self):
->>>>>>> master:django/db/models/sql/query.py
q = self.clone()
q.add_extra({'a': 1}, None, None, None, None, None)
q.add_fields(())
@@ -353,104 +344,8 @@ class Query(object):
q.set_aggregate_mask(())
q.clear_ordering()
q.set_limits(high=1)
-<<<<<<< HEAD:django/db/models/sql/query.py
compiler = q.get_compiler(using=using)
return bool(compiler.execute_sql(SINGLE))
-=======
- return bool(q.execute_sql(SINGLE))
-
- def as_sql(self, with_limits=True, with_col_aliases=False):
- """
- Creates the SQL for this query. Returns the SQL string and list of
- parameters.
-
- If 'with_limits' is False, any limit/offset information is not included
- in the query.
- """
- self.pre_sql_setup()
- out_cols = self.get_columns(with_col_aliases)
- ordering, ordering_group_by = self.get_ordering()
-
- # This must come after 'select' and 'ordering' -- see docstring of
- # get_from_clause() for details.
- from_, f_params = self.get_from_clause()
-
- qn = self.quote_name_unless_alias
- where, w_params = self.where.as_sql(qn=qn)
- having, h_params = self.having.as_sql(qn=qn)
- params = []
- for val in self.extra_select.itervalues():
- params.extend(val[1])
-
- result = ['SELECT']
- if self.distinct:
- result.append('DISTINCT')
- result.append(', '.join(out_cols + self.ordering_aliases))
-
- result.append('FROM')
- result.extend(from_)
- params.extend(f_params)
-
- if where:
- result.append('WHERE %s' % where)
- params.extend(w_params)
- if self.extra_where:
- if not where:
- result.append('WHERE')
- else:
- result.append('AND')
- result.append(' AND '.join(self.extra_where))
-
- grouping, gb_params = self.get_grouping()
- if grouping:
- if ordering:
- # If the backend can't group by PK (i.e., any database
- # other than MySQL), then any fields mentioned in the
- # ordering clause needs to be in the group by clause.
- if not self.connection.features.allows_group_by_pk:
- for col, col_params in ordering_group_by:
- if col not in grouping:
- grouping.append(str(col))
- gb_params.extend(col_params)
- else:
- ordering = self.connection.ops.force_no_ordering()
- result.append('GROUP BY %s' % ', '.join(grouping))
- params.extend(gb_params)
-
- if having:
- result.append('HAVING %s' % having)
- params.extend(h_params)
-
- if ordering:
- result.append('ORDER BY %s' % ', '.join(ordering))
-
- if with_limits:
- if self.high_mark is not None:
- result.append('LIMIT %d' % (self.high_mark - self.low_mark))
- if self.low_mark:
- if self.high_mark is None:
- val = self.connection.ops.no_limit_value()
- if val:
- result.append('LIMIT %d' % val)
- result.append('OFFSET %d' % self.low_mark)
-
- params.extend(self.extra_params)
- return ' '.join(result), tuple(params)
-
- def as_nested_sql(self):
- """
- Perform the same functionality as the as_sql() method, returning an
- SQL string and parameters. However, the alias prefixes are bumped
- beforehand (in a copy -- the current query isn't changed) and any
- ordering is removed.
-
- Used when nesting this query inside another.
- """
- obj = self.clone()
- obj.clear_ordering(True)
- obj.bump_prefix()
- return obj.as_sql()
->>>>>>> master:django/db/models/sql/query.py
def combine(self, rhs, connector):
"""
diff --git a/django/db/models/sql/subqueries.py b/django/db/models/sql/subqueries.py
index be4689820f..f9b565181d 100644
--- a/django/db/models/sql/subqueries.py
+++ b/django/db/models/sql/subqueries.py
@@ -191,7 +191,7 @@ class InsertQuery(Query):
extras.update(kwargs)
return super(InsertQuery, self).clone(klass, **extras)
- def insert_values(self, insert_values, raw_values=False):
+ def insert_values(self, insert_values, connection, raw_values=False):
"""
Set up the insert query from the 'insert_values' dictionary. The
dictionary gives the model field names and their target values.
@@ -206,7 +206,7 @@ class InsertQuery(Query):
if hasattr(field, 'get_placeholder'):
# Some fields (e.g. geo fields) need special munging before
# they can be inserted.
- placeholders.append(field.get_placeholder(val))
+ placeholders.append(field.get_placeholder(val, connection))
else:
placeholders.append('%s')