summaryrefslogtreecommitdiff
path: root/django/db/backends/sqlite3/operations.py
diff options
context:
space:
mode:
authormyoungjinGo <myoungjingo.dev@gmail.com>2025-07-16 00:43:45 +0900
committerJacob Walls <jacobtylerwalls@gmail.com>2025-11-07 16:41:57 -0500
commitc4e07f94ebc1f9eaa3dae7b3dc6a2b9832182a10 (patch)
tree8e0defebd666a67265844f0fba790b4621e769f4 /django/db/backends/sqlite3/operations.py
parent1c7db70e79dce82f50d5958da64ab8e2807a31df (diff)
Fixed #36420 -- Used actual SQLite limits in last_executed_query() quoting.
Diffstat (limited to 'django/db/backends/sqlite3/operations.py')
-rw-r--r--django/db/backends/sqlite3/operations.py18
1 files changed, 9 insertions, 9 deletions
diff --git a/django/db/backends/sqlite3/operations.py b/django/db/backends/sqlite3/operations.py
index 1500ae28aa..ac98324b2e 100644
--- a/django/db/backends/sqlite3/operations.py
+++ b/django/db/backends/sqlite3/operations.py
@@ -1,5 +1,6 @@
import datetime
import decimal
+import sqlite3
import uuid
from functools import lru_cache
from itertools import chain
@@ -143,16 +144,15 @@ 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 parameters, 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:
+ connection = self.connection.connection
+ variable_limit = self.connection.features.max_query_params
+ column_limit = connection.getlimit(sqlite3.SQLITE_LIMIT_COLUMN)
+ batch_size = min(variable_limit, column_limit)
+
+ if len(params) > batch_size:
results = ()
- for index in range(0, len(params), BATCH_SIZE):
- chunk = params[index : index + BATCH_SIZE]
+ 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