# Temporarily limit a database connection parameter
@contextlib.contextmanager
-def cx_limit(cx, category=sqlite.SQLITE_LIMIT_LENGTH, limit=128):
+def cx_limit(cx, category=sqlite.SQLITE_LIMIT_SQL_LENGTH, limit=128):
try:
_prev = cx.setlimit(category, limit)
yield limit
prev_limit = self.cx.setlimit(category, new_limit)
self.assertEqual(saved_limit, prev_limit)
self.assertEqual(self.cx.getlimit(category), new_limit)
- msg = "string or blob too big"
+ msg = "query string is too large"
self.assertRaisesRegex(sqlite.DataError, msg,
self.cx.execute, "select 1 as '16'")
finally: # restore saved limit
def test_cursor_executescript_too_large_script(self):
msg = "query string is too large"
with memory_database() as cx, cx_limit(cx) as lim:
- cx.executescript("select 'almost too large'".ljust(lim-1))
+ cx.executescript("select 'almost too large'".ljust(lim))
with self.assertRaisesRegex(sqlite.DataError, msg):
- cx.executescript("select 'too large'".ljust(lim))
+ cx.executescript("select 'too large'".ljust(lim+1))
def test_cursor_executescript_tx_control(self):
con = sqlite.connect(":memory:")
with memory_database() as cx, cx_limit(cx) as lim:
cu = cx.cursor()
- cx("select 1".ljust(lim-1))
+ cx("select 1".ljust(lim))
# use a different SQL statement; don't reuse from the LRU cache
- cu.execute("select 2".ljust(lim-1))
+ cu.execute("select 2".ljust(lim))
- sql = "select 3".ljust(lim)
+ sql = "select 3".ljust(lim+1)
self.assertRaisesRegex(sqlite.DataError, msg, cx, sql)
self.assertRaisesRegex(sqlite.DataError, msg, cu.execute, sql)
--- /dev/null
+Fix a regression in Python 3.11a1 and 3.11a2 where :mod:`sqlite3`
+incorrectly would use ``SQLITE_LIMIT_LENGTH`` when checking SQL statement
+lengths. Now, ``SQLITE_LIMIT_SQL_LENGTH`` is used. Patch by Erlend E. Aasland.
size_t sql_len = strlen(sql_script);
int max_length = sqlite3_limit(self->connection->db,
- SQLITE_LIMIT_LENGTH, -1);
- if (sql_len >= (unsigned)max_length) {
+ SQLITE_LIMIT_SQL_LENGTH, -1);
+ if (sql_len > (unsigned)max_length) {
PyErr_SetString(self->connection->DataError,
"query string is too large");
return NULL;
}
sqlite3 *db = connection->db;
- int max_length = sqlite3_limit(db, SQLITE_LIMIT_LENGTH, -1);
- if (size >= max_length) {
+ int max_length = sqlite3_limit(db, SQLITE_LIMIT_SQL_LENGTH, -1);
+ if (size > max_length) {
PyErr_SetString(connection->DataError,
"query string is too large");
return NULL;