Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #350 -- 'offset' DB API parameter now works in MySQL 3. Tests f…

…rom [540] pass. Thanks, ronan@cremin.com

git-svn-id: http://code.djangoproject.com/svn/django/trunk@541 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit e5e1ea602d9393a29400098dc40d0f9de846fdd1 1 parent 9180112
@adrianholovaty adrianholovaty authored
View
1  django/core/db/__init__.py
@@ -37,6 +37,7 @@
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
6 django/core/db/backends/mysql.py
@@ -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
6 django/core/db/backends/postgresql.py
@@ -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
6 django/core/db/backends/sqlite3.py
@@ -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
5 django/core/meta/__init__.py
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.