Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Refactored get_limit_offset_sql() to DatabaseOperations.limit_offset_…

…sql(). Refs #5106

git-svn-id: http://code.djangoproject.com/svn/django/trunk@5959 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit d3e69c3a47dd9fc7c36414c029d9919b84b0b822 1 parent 5ce050a
@adrianholovaty adrianholovaty authored
View
10 django/db/backends/__init__.py
@@ -109,3 +109,13 @@ def last_insert_id(self, cursor, table_name, pk_name):
column.
"""
return cursor.lastrowid
+
+ def limit_offset_sql(self, limit, offset=None):
+ """
+ Returns a LIMIT/OFFSET SQL clause, given a limit and optional offset.
+ """
+ # 'LIMIT 40 OFFSET 20'
+ sql = "LIMIT %s" % limit
+ if offset and offset != 0:
+ sql += " OFFSET %s" % offset
+ return sql
View
7 django/db/backends/ado_mssql/base.py
@@ -100,13 +100,6 @@ def quote_name(name):
dictfetchmany = util.dictfetchmany
dictfetchall = util.dictfetchall
-def get_limit_offset_sql(limit, offset=None):
- # TODO: This is a guess. Make sure this is correct.
- sql = "LIMIT %s" % limit
- if offset and offset != 0:
- sql += " OFFSET %s" % offset
- return sql
-
def get_random_function_sql():
return "RAND()"
View
1  django/db/backends/dummy/base.py
@@ -43,7 +43,6 @@ def close(self):
dictfetchone = complain
dictfetchmany = complain
dictfetchall = complain
-get_limit_offset_sql = complain
get_random_function_sql = complain
get_pk_default_value = complain
get_max_name_length = ignore
View
13 django/db/backends/mysql/base.py
@@ -77,6 +77,13 @@ def drop_foreignkey_sql(self):
def fulltext_search_sql(self, field_name):
return 'MATCH (%s) AGAINST (%%s IN BOOLEAN MODE)' % field_name
+ def limit_offset_sql(self, limit, offset=None):
+ # 'LIMIT 20,40'
+ sql = "LIMIT "
+ if offset and offset != 0:
+ sql += "%s," % offset
+ return sql + str(limit)
+
class DatabaseWrapper(BaseDatabaseWrapper):
ops = DatabaseOperations()
@@ -155,12 +162,6 @@ def quote_name(name):
dictfetchmany = util.dictfetchmany
dictfetchall = util.dictfetchall
-def get_limit_offset_sql(limit, offset=None):
- sql = "LIMIT "
- if offset and offset != 0:
- sql += "%s," % offset
- return sql + str(limit)
-
def get_random_function_sql():
return "RAND()"
View
13 django/db/backends/mysql_old/base.py
@@ -87,6 +87,13 @@ def drop_foreignkey_sql(self):
def fulltext_search_sql(self, field_name):
return 'MATCH (%s) AGAINST (%%s IN BOOLEAN MODE)' % field_name
+ def limit_offset_sql(self, limit, offset=None):
+ # 'LIMIT 20,40'
+ sql = "LIMIT "
+ if offset and offset != 0:
+ sql += "%s," % offset
+ return sql + str(limit)
+
class DatabaseWrapper(BaseDatabaseWrapper):
ops = DatabaseOperations()
@@ -174,12 +181,6 @@ def quote_name(name):
dictfetchmany = util.dictfetchmany
dictfetchall = util.dictfetchall
-def get_limit_offset_sql(limit, offset=None):
- sql = "LIMIT "
- if offset and offset != 0:
- sql += "%s," % offset
- return sql + str(limit)
-
def get_random_function_sql():
return "RAND()"
View
10 django/db/backends/oracle/base.py
@@ -62,6 +62,11 @@ def last_insert_id(self, cursor, table_name, pk_name):
cursor.execute('SELECT %s_sq.currval FROM dual' % sq_name)
return cursor.fetchone()[0]
+ def limit_offset_sql(self, limit, offset=None):
+ # Limits and offset are too complicated to be handled here.
+ # Instead, they are handled in django/db/backends/oracle/query.py.
+ return ""
+
class DatabaseWrapper(BaseDatabaseWrapper):
ops = DatabaseOperations()
@@ -178,11 +183,6 @@ def get_field_cast_sql(db_type):
else:
return "%s%s"
-def get_limit_offset_sql(limit, offset=None):
- # Limits and offset are too complicated to be handled here.
- # Instead, they are handled in django/db/backends/oracle/query.py.
- return ""
-
def get_random_function_sql():
return "DBMS_RANDOM.RANDOM"
View
6 django/db/backends/postgresql/base.py
@@ -131,12 +131,6 @@ def dictfetchall(cursor):
"Returns all rows from a cursor as a dict"
return cursor.dictfetchall()
-def get_limit_offset_sql(limit, offset=None):
- sql = "LIMIT %s" % limit
- if offset and offset != 0:
- sql += " OFFSET %s" % offset
- return sql
-
def get_random_function_sql():
return "RANDOM()"
View
6 django/db/backends/postgresql_psycopg2/base.py
@@ -85,12 +85,6 @@ def quote_name(name):
dictfetchmany = util.dictfetchmany
dictfetchall = util.dictfetchall
-def get_limit_offset_sql(limit, offset=None):
- sql = "LIMIT %s" % limit
- if offset and offset != 0:
- sql += " OFFSET %s" % offset
- return sql
-
def get_random_function_sql():
return "RANDOM()"
View
6 django/db/backends/sqlite3/base.py
@@ -115,12 +115,6 @@ def _sqlite_extract(lookup_type, dt):
return None
return str(getattr(dt, lookup_type))
-def get_limit_offset_sql(limit, offset=None):
- sql = "LIMIT %s" % limit
- if offset and offset != 0:
- sql += " OFFSET %s" % offset
- return sql
-
def get_random_function_sql():
return "RANDOM()"
View
2  django/db/models/query.py
@@ -555,7 +555,7 @@ def _get_sql_clause(self):
# LIMIT and OFFSET clauses
if self._limit is not None:
- sql.append("%s " % backend.get_limit_offset_sql(self._limit, self._offset))
+ sql.append("%s " % connection.ops.limit_offset_sql(self._limit, self._offset))
else:
assert self._offset is None, "'offset' is not allowed without 'limit'"
Please sign in to comment.
Something went wrong with that request. Please try again.