summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2016-01-09 21:30:19 +0100
committerAymeric Augustin <aymeric.augustin@m4x.org>2016-01-21 10:48:47 +0100
commitcfe4ba6e905eefc7e53de37226e0f342a68dc47b (patch)
treee3a9a2dfcb0fd0aec9377a9ed3f361a350e90255 /django
parent05e8fa83c378c882ab4d4a1012ce954a9dced6de (diff)
[1.9.x] Fixed #26063 -- Crash when passing > 2000 params.
If SQLITE_MAX_VARIABLE_NUMBER (default = 999) is changed at compile time to be greater than SQLITE_MAX_COLUMN (default = 2000), which Debian does by setting the former to 250000, Django raised an exception on queries containing more than 2000 parameters when DEBUG = True. Backport of f91b5a7e4b from master
Diffstat (limited to 'django')
-rw-r--r--django/db/backends/sqlite3/operations.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/django/db/backends/sqlite3/operations.py b/django/db/backends/sqlite3/operations.py
index 91d1a27f8a..1a4f4baa6c 100644
--- a/django/db/backends/sqlite3/operations.py
+++ b/django/db/backends/sqlite3/operations.py
@@ -107,6 +107,19 @@ class DatabaseOperations(BaseDatabaseOperations):
"""
Only for last_executed_query! Don't use this to execute SQL queries!
"""
+ # This function is limited both by SQLITE_LIMIT_VARIABLE_NUMBER (the
+ # number of paramters, default = 999) and SQLITE_MAX_COLUMN (the
+ # number of return values, default = 2000). Since Python's sqlite3
+ # module doesn't expose the get_limit() C API, assume the default
+ # limits are in effect and split the work in batches if needed.
+ BATCH_SIZE = 999
+ if len(params) > BATCH_SIZE:
+ results = ()
+ for index in range(0, len(params), BATCH_SIZE):
+ chunk = params[index:index + BATCH_SIZE]
+ results += self._quote_params_for_last_executed_query(chunk)
+ return results
+
sql = 'SELECT ' + ', '.join(['QUOTE(?)'] * len(params))
# Bypass Django's wrappers and use the underlying sqlite3 connection
# to avoid logging this query - it would trigger infinite recursion.