diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2008-02-23 01:34:49 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2008-02-23 01:34:49 +0000 |
| commit | 7355fa6b728357a3e7257fbe1175d68a0d7e2ec1 (patch) | |
| tree | 04f384b99607f4dd9e7ef94d1d2399dcfdbc891f /django | |
| parent | e2f524ca09bacef4545b56dc3f136655fa0b912c (diff) | |
queryset-refactor: Implemented slicing to end of querysets.
Refs #2150, #5012.
git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@7147 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/backends/__init__.py | 8 | ||||
| -rw-r--r-- | django/db/backends/mysql/base.py | 4 | ||||
| -rw-r--r-- | django/db/backends/mysql_old/base.py | 4 | ||||
| -rw-r--r-- | django/db/backends/postgresql/operations.py | 3 | ||||
| -rw-r--r-- | django/db/backends/sqlite3/base.py | 3 | ||||
| -rw-r--r-- | django/db/models/sql/query.py | 6 |
6 files changed, 27 insertions, 1 deletions
diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py index a4c5a25589..6ba06f083a 100644 --- a/django/db/backends/__init__.py +++ b/django/db/backends/__init__.py @@ -183,6 +183,14 @@ class BaseDatabaseOperations(object): """ return None + def no_limit_value(self): + """ + Returns the value to use for the LIMIT when we are wanting "LIMIT + infinity". Returns None if the limit clause can be omitted in this case. + """ + # FIXME: API may need to change once Oracle backend is repaired. + raise NotImplementedError() + def pk_default_value(self): """ Returns the value to use during an INSERT statement to specify that diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py index 697dcd3a67..c2b2c7ab1c 100644 --- a/django/db/backends/mysql/base.py +++ b/django/db/backends/mysql/base.py @@ -93,6 +93,10 @@ class DatabaseOperations(BaseDatabaseOperations): sql += "%s," % offset return sql + str(limit) + def no_limit_value(self): + # 2**64 - 1, as recommended by the MySQL documentation + return 18446744073709551615L + def quote_name(self, name): if name.startswith("`") and name.endswith("`"): return name # Quoting once is enough. diff --git a/django/db/backends/mysql_old/base.py b/django/db/backends/mysql_old/base.py index c22094b968..374e9af1f5 100644 --- a/django/db/backends/mysql_old/base.py +++ b/django/db/backends/mysql_old/base.py @@ -98,6 +98,10 @@ class DatabaseOperations(BaseDatabaseOperations): sql += "%s," % offset return sql + str(limit) + def no_limit_value(self): + # 2**64 - 1, as recommended by the MySQL documentation + return 18446744073709551615L + def quote_name(self, name): if name.startswith("`") and name.endswith("`"): return name # Quoting once is enough. diff --git a/django/db/backends/postgresql/operations.py b/django/db/backends/postgresql/operations.py index 20392b238e..d2c65a8753 100644 --- a/django/db/backends/postgresql/operations.py +++ b/django/db/backends/postgresql/operations.py @@ -31,6 +31,9 @@ class DatabaseOperations(BaseDatabaseOperations): cursor.execute("SELECT CURRVAL('\"%s_%s_seq\"')" % (table_name, pk_name)) return cursor.fetchone()[0] + def no_limit_value(self): + return None + def quote_name(self, name): if name.startswith('"') and name.endswith('"'): return name # Quoting once is enough. diff --git a/django/db/backends/sqlite3/base.py b/django/db/backends/sqlite3/base.py index b4b445cd16..b8bf5c8f0b 100644 --- a/django/db/backends/sqlite3/base.py +++ b/django/db/backends/sqlite3/base.py @@ -63,6 +63,9 @@ class DatabaseOperations(BaseDatabaseOperations): return name # Quoting once is enough. return '"%s"' % name + def no_limit_value(self): + return -1 + def sql_flush(self, style, tables, sequences): # NB: The generated SQL below is specific to SQLite # Note: The DELETE FROM... SQL generated below works for SQLite databases diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index 20dcb4b71d..f251730c48 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -262,11 +262,15 @@ class Query(object): if ordering: result.append('ORDER BY %s' % ', '.join(ordering)) + # FIXME: Pull this out to make life easier for Oracle et al. if with_limits: if self.high_mark: result.append('LIMIT %d' % (self.high_mark - self.low_mark)) if self.low_mark: - assert self.high_mark, "'offset' is not allowed without 'limit'" + if not self.high_mark: + val = self.connection.ops.no_limit_value() + if val: + result.append('LIMIT %d' % val) result.append('OFFSET %d' % self.low_mark) params.extend(self.extra_params) |
