Skip to content

Commit

Permalink
Refactored get_limit_offset_sql() to DatabaseOperations.limit_offset_…
Browse files Browse the repository at this point in the history
…sql(). Refs #5106

git-svn-id: http://code.djangoproject.com/svn/django/trunk@5959 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
adrianholovaty committed Aug 19, 2007
1 parent 5ce050a commit d3e69c3
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 44 deletions.
10 changes: 10 additions & 0 deletions django/db/backends/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 0 additions & 7 deletions django/db/backends/ado_mssql/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()"

Expand Down
1 change: 0 additions & 1 deletion django/db/backends/dummy/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 7 additions & 6 deletions django/db/backends/mysql/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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()"

Expand Down
13 changes: 7 additions & 6 deletions django/db/backends/mysql_old/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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()"

Expand Down
10 changes: 5 additions & 5 deletions django/db/backends/oracle/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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"

Expand Down
6 changes: 0 additions & 6 deletions django/db/backends/postgresql/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()"

Expand Down
6 changes: 0 additions & 6 deletions django/db/backends/postgresql_psycopg2/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()"

Expand Down
6 changes: 0 additions & 6 deletions django/db/backends/sqlite3/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()"

Expand Down
2 changes: 1 addition & 1 deletion django/db/models/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'"

Expand Down

0 comments on commit d3e69c3

Please sign in to comment.