Changeset 4475
- Timestamp:
- 02/09/07 23:38:38 (2 years ago)
- Files:
-
- django/trunk/django/db/models/query.py (modified) (5 diffs)
- django/trunk/tests/modeltests/lookup/models.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/db/models/query.py
r4470 r4475 168 168 def iterator(self): 169 169 "Performs the SELECT database lookup of this QuerySet." 170 # self._select is a dictionary, and dictionaries' key order is171 # undefined, so we convert it to a list of tuples.172 extra_select = self._select.items()173 174 cursor = connection.cursor()175 176 170 try: 177 171 select, sql, params = self._get_sql_clause() 178 172 except EmptyResultSet: 179 173 raise StopIteration 180 174 175 # self._select is a dictionary, and dictionaries' key order is 176 # undefined, so we convert it to a list of tuples. 177 extra_select = self._select.items() 178 179 cursor = connection.cursor() 181 180 cursor.execute("SELECT " + (self._distinct and "DISTINCT " or "") + ",".join(select) + sql, params) 182 181 fill_cache = self._select_related … … 524 523 525 524 class ValuesQuerySet(QuerySet): 526 def iterator(self): 525 def __init__(self, *args, **kwargs): 526 super(ValuesQuerySet, self).__init__(*args, **kwargs) 527 527 # select_related and select aren't supported in values(). 528 528 self._select_related = False 529 529 self._select = {} 530 531 def iterator(self): 532 try: 533 select, sql, params = self._get_sql_clause() 534 except EmptyResultSet: 535 raise StopIteration 530 536 531 537 # self._fields is a list of field names to fetch. … … 536 542 columns = [f.column for f in self.model._meta.fields] 537 543 field_names = [f.attname for f in self.model._meta.fields] 538 539 cursor = connection.cursor()540 541 try:542 select, sql, params = self._get_sql_clause()543 except EmptyResultSet:544 raise StopIteration545 544 546 545 select = ['%s.%s' % (backend.quote_name(self.model._meta.db_table), backend.quote_name(c)) for c in columns] 546 cursor = connection.cursor() 547 547 cursor.execute("SELECT " + (self._distinct and "DISTINCT " or "") + ",".join(select) + sql, params) 548 548 while 1: … … 593 593 self._result_cache = [] 594 594 595 def iterator(self):596 raise StopIteration597 598 595 def count(self): 599 596 return 0 … … 606 603 c._result_cache = [] 607 604 return c 605 606 def _get_sql_clause(self): 607 raise EmptyResultSet 608 608 609 609 class QOperator(object): django/trunk/tests/modeltests/lookup/models.py
r4470 r4475 199 199 >>> Article.objects.none().count() 200 200 0 201 >>> [article for article in Article.objects.none().iterator()] 202 [] 201 203 202 204 # using __in with an empty list should return an empty query set
