Fixed #350 -- 'offset' DB API parameter now works in MySQL 3. Tests from [540] pass. Thanks, ronan@cremin.com

git-svn-id: http://code.djangoproject.com/svn/django/trunk@541 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2005-08-19 21:51:14 +00:00
parent 9180112f02
commit e5e1ea602d
5 changed files with 21 additions and 3 deletions

View File

@ -37,6 +37,7 @@ dictfetchall = dbmod.dictfetchall
get_last_insert_id = dbmod.get_last_insert_id
get_date_extract_sql = dbmod.get_date_extract_sql
get_date_trunc_sql = dbmod.get_date_trunc_sql
get_limit_offset_sql = dbmod.get_limit_offset_sql
get_table_list = dbmod.get_table_list
get_relations = dbmod.get_relations
OPERATOR_MAPPING = dbmod.OPERATOR_MAPPING

View File

@ -71,6 +71,12 @@ def get_date_trunc_sql(lookup_type, field_name):
subtractions.append(" - interval (DATE_FORMAT(%s, '%%%%m')-1) month" % field_name)
return "(%s - %s)" % (field_name, ''.join(subtractions))
def get_limit_offset_sql(limit, offset=None):
sql = "LIMIT "
if offset and offset != 0:
sql += "%s," % offset
return sql + str(limit)
def get_table_list(cursor):
"Returns a list of table names in the current database."
cursor.execute("SHOW TABLES")

View File

@ -71,6 +71,12 @@ def get_date_trunc_sql(lookup_type, field_name):
# http://www.postgresql.org/docs/8.0/static/functions-datetime.html#FUNCTIONS-DATETIME-TRUNC
return "DATE_TRUNC('%s', %s)" % (lookup_type, field_name)
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_table_list(cursor):
"Returns a list of table names in the current database."
cursor.execute("""

View File

@ -97,6 +97,12 @@ def get_date_trunc_sql(lookup_type, field_name):
# sqlite doesn't support DATE_TRUNC, so we fake it as above.
return 'django_date_trunc("%s", %s)' % (lookup_type.lower(), field_name)
def get_limit_offset_sql(limit, offset=None):
sql = "LIMIT %s" % limit
if offset and offset != 0:
sql += " OFFSET %s" % offset
return sql
def _sqlite_date_trunc(lookup_type, dt):
try:
dt = typecasts.typecast_timestamp(dt)

View File

@ -1277,10 +1277,9 @@ def function_get_sql_clause(opts, **kwargs):
# LIMIT and OFFSET clauses
if kwargs.get('limit') is not None:
limit_sql = " LIMIT %s " % kwargs['limit']
if kwargs.get('offset') is not None and kwargs['offset'] != 0:
limit_sql += "OFFSET %s " % kwargs['offset']
limit_sql = " %s " % db.get_limit_offset_sql(kwargs['limit'], kwargs.get('offset'))
else:
assert kwargs.get('offset') is None, "'offset' is not allowed without 'limit'"
limit_sql = ""
return select, " FROM " + ",".join(tables) + (where and " WHERE " + " AND ".join(where) or "") + (order_by and " ORDER BY " + order_by or "") + limit_sql, params