Index: where.py
===================================================================
--- where.py	(.../mirror/django/trunk/django/db/models/sql)	(revision 5354)
+++ where.py	(.../local/django/mymultidb/django/db/models/sql)	(working copy)
@@ -4,11 +4,12 @@
 import datetime
 
 from django.utils import tree
-from django.db import connection
 from django.db.models.fields import Field
 from django.db.models.query_utils import QueryWrapper
 from datastructures import EmptyResultSet, FullResultSet
 
+from copy import deepcopy
+
 # Connection types
 AND = 'AND'
 OR = 'OR'
@@ -26,6 +27,20 @@
     """
     default = AND
 
+    def __init__(self, connection, *args, **kwargs):
+        self.connection = connection
+        super(WhereNode, self).__init__(*args, **kwargs)
+
+    def __deepcopy__(self, memo):
+        x = WhereNode.__new__(WhereNode)
+        memo[id(self)] = x
+        for n, v in self.__dict__.iteritems():
+            if n != 'connection':
+                setattr(x, n, deepcopy(v, memo))
+            else:
+                setattr(x, n, self.connection)
+        return x
+
     def as_sql(self, node=None, qn=None):
         """
         Returns the SQL version of the where clause and the value to be
@@ -38,7 +53,7 @@
         if node is None:
             node = self
         if not qn:
-            qn = connection.ops.quote_name
+            qn = self.connection.ops.quote_name
         if not node.children:
             return None, []
         result = []
@@ -99,11 +114,12 @@
             lhs = '%s.%s' % (qn(table_alias), qn(name))
         else:
             lhs = qn(name)
+
         db_type = field and field.db_type() or None
-        field_sql = connection.ops.field_cast_sql(db_type) % lhs
-
+        field_sql = self.connection.ops.field_cast_sql(db_type) % lhs
+        
         if isinstance(value, datetime.datetime):
-            cast_sql = connection.ops.datetime_cast_sql()
+            cast_sql = self.connection.ops.datetime_cast_sql()
         else:
             cast_sql = '%s'
 
@@ -116,11 +132,11 @@
         else:
             extra = ''
 
-        if lookup_type in connection.operators:
-            format = "%s %%s %s" % (connection.ops.lookup_cast(lookup_type),
+        if lookup_type in self.connection.operators:
+            format = "%s %%s %s" % (self.connection.ops.lookup_cast(lookup_type),
                     extra)
             return (format % (field_sql,
-                    connection.operators[lookup_type] % cast_sql), params)
+                    self.connection.operators[lookup_type] % cast_sql), params)
 
         if lookup_type == 'in':
             if not value:
@@ -132,15 +148,15 @@
         elif lookup_type in ('range', 'year'):
             return ('%s BETWEEN %%s and %%s' % field_sql, params)
         elif lookup_type in ('month', 'day'):
-            return ('%s = %%s' % connection.ops.date_extract_sql(lookup_type,
+            return ('%s = %%s' % self.connection.ops.date_extract_sql(lookup_type,
                     field_sql), params)
         elif lookup_type == 'isnull':
             return ('%s IS %sNULL' % (field_sql, (not value and 'NOT ' or '')),
                     params)
         elif lookup_type == 'search':
-            return (connection.ops.fulltext_search_sql(field_sql), params)
+            return (self.connection.ops.fulltext_search_sql(field_sql), params)
         elif lookup_type in ('regex', 'iregex'):
-            return connection.ops.regex_lookup(lookup_type) % (field_sql, cast_sql), params
+            return self.connection.ops.regex_lookup(lookup_type) % (field_sql, cast_sql), params
 
         raise TypeError('Invalid lookup_type: %r' % lookup_type)
 
Index: query.py
===================================================================
--- query.py	(.../mirror/django/trunk/django/db/models/sql)	(revision 5354)
+++ query.py	(.../local/django/mymultidb/django/db/models/sql)	(working copy)
@@ -60,7 +60,7 @@
         # SQL-related attributes
         self.select = []
         self.tables = []    # Aliases in the order they are created.
-        self.where = where()
+        self.where = where(self.connection)
         self.where_class = where
         self.group_by = []
         self.having = []
@@ -215,7 +215,7 @@
         obj.related_select_cols = []
         obj.related_select_fields = []
         if obj.distinct and len(obj.select) > 1:
-            obj = self.clone(CountQuery, _query=obj, where=self.where_class(),
+            obj = self.clone(CountQuery, _query=obj, where=self.where_class(self.connection),
                     distinct=False)
             obj.select = []
             obj.extra_select = {}
@@ -346,10 +346,10 @@
                 self.where.add(EverythingNode(), AND)
         elif self.where:
             # rhs has an empty where clause.
-            w = self.where_class()
+            w = self.where_class(self.connection)
             w.add(EverythingNode(), AND)
         else:
-            w = self.where_class()
+            w = self.where_class(self.connection)
         self.where.add(w, connector)
 
         # Selection columns and extra extensions are those provided by 'rhs'.
Index: subqueries.py
===================================================================
--- subqueries.py	(.../mirror/django/trunk/django/db/models/sql)	(revision 5354)
+++ subqueries.py	(.../local/django/mymultidb/django/db/models/sql)	(working copy)
@@ -47,7 +47,7 @@
         for related in cls._meta.get_all_related_many_to_many_objects():
             if not isinstance(related.field, generic.GenericRelation):
                 for offset in range(0, len(pk_list), GET_ITERATOR_CHUNK_SIZE):
-                    where = self.where_class()
+                    where = self.where_class(self.connection)
                     where.add((None, related.field.m2m_reverse_name(),
                             related.field, 'in',
                             pk_list[offset : offset+GET_ITERATOR_CHUNK_SIZE]),
@@ -55,14 +55,14 @@
                     self.do_query(related.field.m2m_db_table(), where)
 
         for f in cls._meta.many_to_many:
-            w1 = self.where_class()
+            w1 = self.where_class(self.connection)
             if isinstance(f, generic.GenericRelation):
                 from django.contrib.contenttypes.models import ContentType
                 field = f.rel.to._meta.get_field(f.content_type_field_name)
                 w1.add((None, field.column, field, 'exact',
                         ContentType.objects.get_for_model(cls).id), AND)
             for offset in range(0, len(pk_list), GET_ITERATOR_CHUNK_SIZE):
-                where = self.where_class()
+                where = self.where_class(self.connection)
                 where.add((None, f.m2m_column_name(), f, 'in',
                         pk_list[offset : offset + GET_ITERATOR_CHUNK_SIZE]),
                         AND)
@@ -79,7 +79,7 @@
         lot of values in pk_list.
         """
         for offset in range(0, len(pk_list), GET_ITERATOR_CHUNK_SIZE):
-            where = self.where_class()
+            where = self.where_class(self.connection)
             field = self.model._meta.pk
             where.add((None, field.column, field, 'in',
                     pk_list[offset : offset + GET_ITERATOR_CHUNK_SIZE]), AND)
@@ -178,7 +178,7 @@
 
         # Now we adjust the current query: reset the where clause and get rid
         # of all the tables we don't need (since they're in the sub-select).
-        self.where = self.where_class()
+        self.where = self.where_class(self.connection)
         if self.related_updates or must_pre_select:
             # Either we're using the idents in multiple update queries (so
             # don't want them to change), or the db backend doesn't support
@@ -202,7 +202,7 @@
         This is used by the QuerySet.delete_objects() method.
         """
         for offset in range(0, len(pk_list), GET_ITERATOR_CHUNK_SIZE):
-            self.where = self.where_class()
+            self.where = self.where_class(self.connection)
             f = self.model._meta.pk
             self.where.add((None, f.column, f, 'in',
                     pk_list[offset : offset + GET_ITERATOR_CHUNK_SIZE]),

Property changes on: .
___________________________________________________________________
Name: svn:ignore
   + *.pyc


