mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
bpo-44165: Optimise sqlite3 statement preparation by passing string size (GH-26206)
This commit is contained in:
parent
ee7637596d
commit
a384b6c040
3 changed files with 25 additions and 7 deletions
|
@ -66,6 +66,12 @@ pysqlite_statement_create(pysqlite_Connection *connection, PyObject *sql)
|
|||
Py_TYPE(sql)->tp_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int max_length = sqlite3_limit(connection->db, SQLITE_LIMIT_LENGTH, -1);
|
||||
if (sql_cstr_len >= max_length) {
|
||||
PyErr_SetString(pysqlite_DataError, "query string is too large");
|
||||
return PYSQLITE_TOO_MUCH_SQL;
|
||||
}
|
||||
if (strlen(sql_cstr) != (size_t)sql_cstr_len) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"the query contains a null character");
|
||||
|
@ -106,7 +112,7 @@ pysqlite_statement_create(pysqlite_Connection *connection, PyObject *sql)
|
|||
Py_BEGIN_ALLOW_THREADS
|
||||
rc = sqlite3_prepare_v2(self->db,
|
||||
sql_cstr,
|
||||
-1,
|
||||
(int)sql_cstr_len + 1,
|
||||
&self->st,
|
||||
&tail);
|
||||
Py_END_ALLOW_THREADS
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue