Author: mtredinnick
Date: 2007-10-13 21:17:12 -0500 (Sat, 13 Oct 2007)
New Revision: 6499
Modified:
django/branches/queryset-refactor/django/db/models/sql/query.py
Log:
queryset-refactor: Fixed a problem with count() queries -- we were creating an
"ORDER BY" clause sometimes and that isn't accepted by PostgreSQL (and a waste
of time on other databases as well).
Modified: django/branches/queryset-refactor/django/db/models/sql/query.py
===================================================================
--- django/branches/queryset-refactor/django/db/models/sql/query.py
2007-10-14 02:16:57 UTC (rev 6498)
+++ django/branches/queryset-refactor/django/db/models/sql/query.py
2007-10-14 02:17:12 UTC (rev 6499)
@@ -161,7 +161,7 @@
Performs a COUNT() query using the current filter constraints.
"""
obj = self.clone()
- obj.clear_ordering()
+ obj.clear_ordering(True)
obj.clear_limits()
obj.select_related = False
if obj.distinct and len(obj.select) > 1:
@@ -394,7 +394,10 @@
"""
Returns a tuple representing the SQL elements in the "order by" clause.
"""
- ordering = self.order_by or self.model._meta.ordering
+ if self.order_by is None:
+ ordering = []
+ else:
+ ordering = self.order_by or self.model._meta.ordering
qn = self.quote_name_unless_alias
opts = self.model._meta
result = []
@@ -798,11 +801,15 @@
"""
self.order_by.extend(ordering)
- def clear_ordering(self):
+ def clear_ordering(self, force_empty=False):
"""
- Removes any ordering settings.
+ Removes any ordering settings. If 'force_empty' is True, there will be
+ no ordering in the resulting query (not even the model's default).
"""
- self.order_by = []
+ if force_empty:
+ self.order_by = None
+ else:
+ self.order_by = []
def add_count_column(self):
"""
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---