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
This commit is contained in:
parent
5ce050a5f5
commit
d3e69c3a47
|
@ -109,3 +109,13 @@ class BaseDatabaseOperations(object):
|
|||
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
|
||||
|
|
|
@ -100,13 +100,6 @@ dictfetchone = util.dictfetchone
|
|||
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()"
|
||||
|
||||
|
|
|
@ -43,7 +43,6 @@ quote_name = complain
|
|||
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
|
||||
|
|
|
@ -77,6 +77,13 @@ class DatabaseOperations(BaseDatabaseOperations):
|
|||
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 @@ dictfetchone = util.dictfetchone
|
|||
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()"
|
||||
|
||||
|
|
|
@ -87,6 +87,13 @@ class DatabaseOperations(BaseDatabaseOperations):
|
|||
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 @@ dictfetchone = util.dictfetchone
|
|||
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()"
|
||||
|
||||
|
|
|
@ -62,6 +62,11 @@ class DatabaseOperations(BaseDatabaseOperations):
|
|||
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"
|
||||
|
||||
|
|
|
@ -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()"
|
||||
|
||||
|
|
|
@ -85,12 +85,6 @@ dictfetchone = util.dictfetchone
|
|||
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()"
|
||||
|
||||
|
|
|
@ -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()"
|
||||
|
||||
|
|
|
@ -555,7 +555,7 @@ class _QuerySet(object):
|
|||
|
||||
# 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'"
|
||||
|
||||
|
|
Loading…
Reference in New Issue