Changeset 7147
- Timestamp:
- 02/22/08 19:34:49 (4 months ago)
- Files:
-
- django/branches/queryset-refactor/django/db/backends/__init__.py (modified) (1 diff)
- django/branches/queryset-refactor/django/db/backends/mysql/base.py (modified) (1 diff)
- django/branches/queryset-refactor/django/db/backends/mysql_old/base.py (modified) (1 diff)
- django/branches/queryset-refactor/django/db/backends/postgresql/operations.py (modified) (1 diff)
- django/branches/queryset-refactor/django/db/backends/sqlite3/base.py (modified) (1 diff)
- django/branches/queryset-refactor/django/db/models/sql/query.py (modified) (1 diff)
- django/branches/queryset-refactor/docs/db-api.txt (modified) (1 diff)
- django/branches/queryset-refactor/tests/modeltests/basic/models.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/queryset-refactor/django/db/backends/__init__.py
r7087 r7147 184 184 return None 185 185 186 def no_limit_value(self): 187 """ 188 Returns the value to use for the LIMIT when we are wanting "LIMIT 189 infinity". Returns None if the limit clause can be omitted in this case. 190 """ 191 # FIXME: API may need to change once Oracle backend is repaired. 192 raise NotImplementedError() 193 186 194 def pk_default_value(self): 187 195 """ django/branches/queryset-refactor/django/db/backends/mysql/base.py
r7136 r7147 93 93 sql += "%s," % offset 94 94 return sql + str(limit) 95 96 def no_limit_value(self): 97 # 2**64 - 1, as recommended by the MySQL documentation 98 return 18446744073709551615L 95 99 96 100 def quote_name(self, name): django/branches/queryset-refactor/django/db/backends/mysql_old/base.py
r6690 r7147 98 98 sql += "%s," % offset 99 99 return sql + str(limit) 100 101 def no_limit_value(self): 102 # 2**64 - 1, as recommended by the MySQL documentation 103 return 18446744073709551615L 100 104 101 105 def quote_name(self, name): django/branches/queryset-refactor/django/db/backends/postgresql/operations.py
r6597 r7147 31 31 cursor.execute("SELECT CURRVAL('\"%s_%s_seq\"')" % (table_name, pk_name)) 32 32 return cursor.fetchone()[0] 33 34 def no_limit_value(self): 35 return None 33 36 34 37 def quote_name(self, name): django/branches/queryset-refactor/django/db/backends/sqlite3/base.py
r6337 r7147 63 63 return name # Quoting once is enough. 64 64 return '"%s"' % name 65 66 def no_limit_value(self): 67 return -1 65 68 66 69 def sql_flush(self, style, tables, sequences): django/branches/queryset-refactor/django/db/models/sql/query.py
r7146 r7147 263 263 result.append('ORDER BY %s' % ', '.join(ordering)) 264 264 265 # FIXME: Pull this out to make life easier for Oracle et al. 265 266 if with_limits: 266 267 if self.high_mark: 267 268 result.append('LIMIT %d' % (self.high_mark - self.low_mark)) 268 269 if self.low_mark: 269 assert self.high_mark, "'offset' is not allowed without 'limit'" 270 if not self.high_mark: 271 val = self.connection.ops.no_limit_value() 272 if val: 273 result.append('LIMIT %d' % val) 270 274 result.append('OFFSET %d' % self.low_mark) 271 275 django/branches/queryset-refactor/docs/db-api.txt
r7136 r7147 422 422 423 423 Entry.objects.all()[5:10] 424 425 You can also slice from the item ''N'' to the end of the queryset. For 426 example, to return everything from the fixth item onwards:: 427 428 Entry.objects.all()[5:] 429 430 How this last example is implemented in SQL varies depending upon the database 431 used, but it is supported in all cases. 424 432 425 433 Generally, slicing a ``QuerySet`` returns a new ``QuerySet`` -- it doesn't django/branches/queryset-refactor/tests/modeltests/basic/models.py
r7136 r7147 293 293 [<Article: Default headline>] 294 294 295 # Note that you can't use 'offset' without 'limit' (on some dbs), so this doesn't work: 296 >>> Article.objects.all()[2:] 297 Traceback (most recent call last): 298 ... 299 AssertionError: 'offset' is not allowed without 'limit' 295 # Using an offset without a limit is also possible. 296 >>> Article.objects.all()[5:] 297 [<Article: Fourth article>, <Article: Article 7>, <Article: Updated article 8>] 300 298 301 299 # Also, once you have sliced you can't filter, re-order or combine
