mirror of https://github.com/django/django.git
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:
parent
9180112f02
commit
e5e1ea602d
|
@ -37,6 +37,7 @@ dictfetchall = dbmod.dictfetchall
|
||||||
get_last_insert_id = dbmod.get_last_insert_id
|
get_last_insert_id = dbmod.get_last_insert_id
|
||||||
get_date_extract_sql = dbmod.get_date_extract_sql
|
get_date_extract_sql = dbmod.get_date_extract_sql
|
||||||
get_date_trunc_sql = dbmod.get_date_trunc_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_table_list = dbmod.get_table_list
|
||||||
get_relations = dbmod.get_relations
|
get_relations = dbmod.get_relations
|
||||||
OPERATOR_MAPPING = dbmod.OPERATOR_MAPPING
|
OPERATOR_MAPPING = dbmod.OPERATOR_MAPPING
|
||||||
|
|
|
@ -71,6 +71,12 @@ def get_date_trunc_sql(lookup_type, field_name):
|
||||||
subtractions.append(" - interval (DATE_FORMAT(%s, '%%%%m')-1) month" % field_name)
|
subtractions.append(" - interval (DATE_FORMAT(%s, '%%%%m')-1) month" % field_name)
|
||||||
return "(%s - %s)" % (field_name, ''.join(subtractions))
|
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):
|
def get_table_list(cursor):
|
||||||
"Returns a list of table names in the current database."
|
"Returns a list of table names in the current database."
|
||||||
cursor.execute("SHOW TABLES")
|
cursor.execute("SHOW TABLES")
|
||||||
|
|
|
@ -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
|
# http://www.postgresql.org/docs/8.0/static/functions-datetime.html#FUNCTIONS-DATETIME-TRUNC
|
||||||
return "DATE_TRUNC('%s', %s)" % (lookup_type, field_name)
|
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):
|
def get_table_list(cursor):
|
||||||
"Returns a list of table names in the current database."
|
"Returns a list of table names in the current database."
|
||||||
cursor.execute("""
|
cursor.execute("""
|
||||||
|
|
|
@ -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.
|
# sqlite doesn't support DATE_TRUNC, so we fake it as above.
|
||||||
return 'django_date_trunc("%s", %s)' % (lookup_type.lower(), field_name)
|
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):
|
def _sqlite_date_trunc(lookup_type, dt):
|
||||||
try:
|
try:
|
||||||
dt = typecasts.typecast_timestamp(dt)
|
dt = typecasts.typecast_timestamp(dt)
|
||||||
|
|
|
@ -1277,10 +1277,9 @@ def function_get_sql_clause(opts, **kwargs):
|
||||||
|
|
||||||
# LIMIT and OFFSET clauses
|
# LIMIT and OFFSET clauses
|
||||||
if kwargs.get('limit') is not None:
|
if kwargs.get('limit') is not None:
|
||||||
limit_sql = " LIMIT %s " % kwargs['limit']
|
limit_sql = " %s " % db.get_limit_offset_sql(kwargs['limit'], kwargs.get('offset'))
|
||||||
if kwargs.get('offset') is not None and kwargs['offset'] != 0:
|
|
||||||
limit_sql += "OFFSET %s " % kwargs['offset']
|
|
||||||
else:
|
else:
|
||||||
|
assert kwargs.get('offset') is None, "'offset' is not allowed without 'limit'"
|
||||||
limit_sql = ""
|
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
|
return select, " FROM " + ",".join(tables) + (where and " WHERE " + " AND ".join(where) or "") + (order_by and " ORDER BY " + order_by or "") + limit_sql, params
|
||||||
|
|
Loading…
Reference in New Issue