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:
Adrian Holovaty 2007-08-19 23:24:59 +00:00
parent 5ce050a5f5
commit d3e69c3a47
10 changed files with 30 additions and 44 deletions

View File

@ -109,3 +109,13 @@ class BaseDatabaseOperations(object):
column. column.
""" """
return cursor.lastrowid 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 File

@ -100,13 +100,6 @@ dictfetchone = util.dictfetchone
dictfetchmany = util.dictfetchmany dictfetchmany = util.dictfetchmany
dictfetchall = util.dictfetchall 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(): def get_random_function_sql():
return "RAND()" return "RAND()"

View File

@ -43,7 +43,6 @@ quote_name = complain
dictfetchone = complain dictfetchone = complain
dictfetchmany = complain dictfetchmany = complain
dictfetchall = complain dictfetchall = complain
get_limit_offset_sql = complain
get_random_function_sql = complain get_random_function_sql = complain
get_pk_default_value = complain get_pk_default_value = complain
get_max_name_length = ignore get_max_name_length = ignore

View File

@ -77,6 +77,13 @@ class DatabaseOperations(BaseDatabaseOperations):
def fulltext_search_sql(self, field_name): def fulltext_search_sql(self, field_name):
return 'MATCH (%s) AGAINST (%%s IN BOOLEAN MODE)' % 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): class DatabaseWrapper(BaseDatabaseWrapper):
ops = DatabaseOperations() ops = DatabaseOperations()
@ -155,12 +162,6 @@ dictfetchone = util.dictfetchone
dictfetchmany = util.dictfetchmany dictfetchmany = util.dictfetchmany
dictfetchall = util.dictfetchall 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(): def get_random_function_sql():
return "RAND()" return "RAND()"

View File

@ -87,6 +87,13 @@ class DatabaseOperations(BaseDatabaseOperations):
def fulltext_search_sql(self, field_name): def fulltext_search_sql(self, field_name):
return 'MATCH (%s) AGAINST (%%s IN BOOLEAN MODE)' % 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): class DatabaseWrapper(BaseDatabaseWrapper):
ops = DatabaseOperations() ops = DatabaseOperations()
@ -174,12 +181,6 @@ dictfetchone = util.dictfetchone
dictfetchmany = util.dictfetchmany dictfetchmany = util.dictfetchmany
dictfetchall = util.dictfetchall 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(): def get_random_function_sql():
return "RAND()" return "RAND()"

View File

@ -62,6 +62,11 @@ class DatabaseOperations(BaseDatabaseOperations):
cursor.execute('SELECT %s_sq.currval FROM dual' % sq_name) cursor.execute('SELECT %s_sq.currval FROM dual' % sq_name)
return cursor.fetchone()[0] 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): class DatabaseWrapper(BaseDatabaseWrapper):
ops = DatabaseOperations() ops = DatabaseOperations()
@ -178,11 +183,6 @@ def get_field_cast_sql(db_type):
else: else:
return "%s%s" 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(): def get_random_function_sql():
return "DBMS_RANDOM.RANDOM" return "DBMS_RANDOM.RANDOM"

View File

@ -131,12 +131,6 @@ def dictfetchall(cursor):
"Returns all rows from a cursor as a dict" "Returns all rows from a cursor as a dict"
return cursor.dictfetchall() 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(): def get_random_function_sql():
return "RANDOM()" return "RANDOM()"

View File

@ -85,12 +85,6 @@ dictfetchone = util.dictfetchone
dictfetchmany = util.dictfetchmany dictfetchmany = util.dictfetchmany
dictfetchall = util.dictfetchall 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(): def get_random_function_sql():
return "RANDOM()" return "RANDOM()"

View File

@ -115,12 +115,6 @@ def _sqlite_extract(lookup_type, dt):
return None return None
return str(getattr(dt, lookup_type)) 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(): def get_random_function_sql():
return "RANDOM()" return "RANDOM()"

View File

@ -555,7 +555,7 @@ class _QuerySet(object):
# LIMIT and OFFSET clauses # LIMIT and OFFSET clauses
if self._limit is not None: 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: else:
assert self._offset is None, "'offset' is not allowed without 'limit'" assert self._offset is None, "'offset' is not allowed without 'limit'"