diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-10-24 04:22:23 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-10-24 04:22:23 +0000 |
| commit | f951d97d9937370a602753f0d530e5b2bbdac69d (patch) | |
| tree | f277fb3b135a5964c52b058f41e9317345afe717 /django/db/models/sql | |
| parent | abcb70e5245095628c4a00816138af9382e306fd (diff) | |
queryset-refactor: Added the ability to apply parameters to the select
fragments in QuerySet.extra(). Refs #2902
git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@6603 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/db/models/sql')
| -rw-r--r-- | django/db/models/sql/query.py | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index c633b8849f..412fe50e21 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -10,7 +10,8 @@ all about the internals of models in order to get the information it needs. import copy import re -from django.utils import tree +from django.utils.tree import Node +from django.utils.datastructures import SortedDict from django.db.models.sql.where import WhereNode, AND, OR from django.db.models.sql.datastructures import Count, Date from django.db.models.fields import FieldDoesNotExist, Field @@ -94,7 +95,7 @@ class Query(object): # These are for extensions. The contents are more or less appended # verbatim to the appropriate clause. - self.extra_select = {} # Maps col_alias -> col_sql. + self.extra_select = SortedDict() # Maps col_alias -> col_sql. self.extra_tables = [] self.extra_where = [] self.extra_params = [] @@ -364,12 +365,8 @@ class Query(object): for f in self.model._meta.fields] aliases = result[:] - # We sort extra_select so that the result columns are in a well-defined - # order (and thus QuerySet.iterator can extract them correctly). - extra_select = self.extra_select.items() - extra_select.sort() result.extend(['(%s) AS %s' % (col, alias) - for alias, col in extra_select]) + for alias, col in self.extra_select.items()]) aliases.extend(self.extra_select.keys()) self._select_aliases = dict.fromkeys(aliases) @@ -761,7 +758,7 @@ class Query(object): return for child in q_object.children: - if isinstance(child, tree.Node): + if isinstance(child, Node): self.where.start_subtree(q_object.connection) self.add_q(child) self.where.end_subtree() @@ -937,7 +934,7 @@ class Query(object): # level. self.distinct = False self.select = [select] - self.extra_select = {} + self.extra_select = SortedDict() def execute_sql(self, result_type=MULTI): """ |
