Author: Alex Date: 2009-06-06 14:38:29 -0500 (Sat, 06 Jun 2009) New Revision: 10934
Modified: django/branches/soc2009/multidb/TODO.TXT django/branches/soc2009/multidb/django/db/models/fields/__init__.py django/branches/soc2009/multidb/django/db/models/sql/query.py django/branches/soc2009/multidb/tests/regressiontests/multiple_database/tests.py Log: [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 Modified: django/branches/soc2009/multidb/TODO.TXT =================================================================== --- django/branches/soc2009/multidb/TODO.TXT 2009-06-06 18:01:43 UTC (rev 10933) +++ django/branches/soc2009/multidb/TODO.TXT 2009-06-06 19:38:29 UTC (rev 10934) @@ -49,7 +49,6 @@ 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`` Modified: django/branches/soc2009/multidb/django/db/models/fields/__init__.py =================================================================== --- django/branches/soc2009/multidb/django/db/models/fields/__init__.py 2009-06-06 18:01:43 UTC (rev 10933) +++ django/branches/soc2009/multidb/django/db/models/fields/__init__.py 2009-06-06 19:38:29 UTC (rev 10934) @@ -204,6 +204,7 @@ 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'): Modified: django/branches/soc2009/multidb/django/db/models/sql/query.py =================================================================== --- django/branches/soc2009/multidb/django/db/models/sql/query.py 2009-06-06 18:01:43 UTC (rev 10933) +++ django/branches/soc2009/multidb/django/db/models/sql/query.py 2009-06-06 19:38:29 UTC (rev 10934) @@ -878,6 +878,9 @@ 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 @@ 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) Modified: django/branches/soc2009/multidb/tests/regressiontests/multiple_database/tests.py =================================================================== --- django/branches/soc2009/multidb/tests/regressiontests/multiple_database/tests.py 2009-06-06 18:01:43 UTC (rev 10933) +++ django/branches/soc2009/multidb/tests/regressiontests/multiple_database/tests.py 2009-06-06 19:38:29 UTC (rev 10934) @@ -49,3 +49,10 @@ 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)) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-updates@googlegroups.com To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-updates?hl=en -~----------~----~----~----~------~----~------~--~---