1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

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).


git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@6499 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Malcolm Tredinnick
2007-10-14 02:17:12 +00:00
parent 90f2893aea
commit bd2dfdf989

View File

@@ -161,7 +161,7 @@ class Query(object):
Performs a COUNT() query using the current filter constraints. Performs a COUNT() query using the current filter constraints.
""" """
obj = self.clone() obj = self.clone()
obj.clear_ordering() obj.clear_ordering(True)
obj.clear_limits() obj.clear_limits()
obj.select_related = False obj.select_related = False
if obj.distinct and len(obj.select) > 1: if obj.distinct and len(obj.select) > 1:
@@ -394,7 +394,10 @@ class Query(object):
""" """
Returns a tuple representing the SQL elements in the "order by" clause. 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 qn = self.quote_name_unless_alias
opts = self.model._meta opts = self.model._meta
result = [] result = []
@@ -798,11 +801,15 @@ class Query(object):
""" """
self.order_by.extend(ordering) 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): def add_count_column(self):
""" """