mirror of
https://github.com/django/django.git
synced 2025-07-05 02:09:13 +00:00
[soc2009/multidb] Fixed the usage of the connection during Query construction, and defer it until actual SQL construction. In practice this means the GROUP BY optimization we do will be correctly applied based on the connection the Query is executed against, as oppossed to the on the QuerySet is targeting at the time the GROUP BY items are added
git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/multidb@10934 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
6aca03c24d
commit
4d6c6d0596
1
TODO.TXT
1
TODO.TXT
@ -49,7 +49,6 @@ that need to be done. I'm trying to be as granular as possible.
|
||||
phase. This involves changing the following methods:
|
||||
|
||||
* ``Query.add_aggregate``
|
||||
* ``Query.set_group_by``
|
||||
* ``DateQuery.add_date_select``
|
||||
* ``Field.get_db_prep_lookup``
|
||||
* ``DateField.get_db_prep_value``
|
||||
|
@ -204,6 +204,7 @@ class Field(object):
|
||||
sql, params = value._as_sql()
|
||||
return QueryWrapper(('(%s)' % sql), params)
|
||||
|
||||
|
||||
if lookup_type in ('regex', 'iregex', 'month', 'day', 'week_day', 'search'):
|
||||
return [value]
|
||||
elif lookup_type in ('exact', 'gt', 'gte', 'lt', 'lte'):
|
||||
|
@ -878,6 +878,9 @@ class BaseQuery(object):
|
||||
qn = self.quote_name_unless_alias
|
||||
result, params = [], []
|
||||
if self.group_by is not None:
|
||||
if len(self.model._meta.fields) == len(self.group_by) and \
|
||||
self.connection.features.allows_group_by_pk:
|
||||
self.group_by = [(self.model._meta.db_table, self.model._meta.pk.column)]
|
||||
group_by = self.group_by or []
|
||||
|
||||
extra_selects = []
|
||||
@ -2099,11 +2102,6 @@ class BaseQuery(object):
|
||||
will be made automatically.
|
||||
"""
|
||||
self.group_by = []
|
||||
if self.connection.features.allows_group_by_pk:
|
||||
if len(self.select) == len(self.model._meta.fields):
|
||||
self.group_by.append((self.model._meta.db_table,
|
||||
self.model._meta.pk.column))
|
||||
return
|
||||
|
||||
for sel in self.select:
|
||||
self.group_by.append(sel)
|
||||
|
@ -49,3 +49,10 @@ class QueryTestCase(TestCase):
|
||||
|
||||
dive = Book.objects.using(db).get(title__icontains="dive")
|
||||
self.assertEqual(dive.title, "Dive into Python")
|
||||
|
||||
dive = Book.objects.using(db).get(title__iexact="dive INTO python")
|
||||
self.assertEqual(dive.title, "Dive into Python")
|
||||
|
||||
pro = Book.objects.using(db).get(published__year=2008)
|
||||
self.assertEqual(pro.title, "Pro Django")
|
||||
self.assertEqual(pro.published, datetime.date(2008, 12, 16))
|
||||
|
Loading…
x
Reference in New Issue
Block a user