mirror of
https://github.com/python/cpython.git
synced 2025-09-09 18:32:22 +00:00
bpo-41662: Fix bugs in binding parameters in sqlite3 (GH-21998)
* When the parameters argument is a list, correctly handle the case
of changing it during iteration.
* When the parameters argument is a custom sequence, no longer
override an exception raised in ``__len__()``.
(cherry picked from commit 0b419b7910
)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
a9ba8ba9a7
commit
f76a3889d1
5 changed files with 34 additions and 3 deletions
|
@ -227,6 +227,9 @@ void pysqlite_statement_bind_parameters(pysqlite_Statement* self, PyObject* para
|
|||
num_params = PyList_GET_SIZE(parameters);
|
||||
} else {
|
||||
num_params = PySequence_Size(parameters);
|
||||
if (num_params == -1) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (num_params != num_params_needed) {
|
||||
PyErr_Format(pysqlite_ProgrammingError,
|
||||
|
@ -238,9 +241,9 @@ void pysqlite_statement_bind_parameters(pysqlite_Statement* self, PyObject* para
|
|||
for (i = 0; i < num_params; i++) {
|
||||
if (PyTuple_CheckExact(parameters)) {
|
||||
current_param = PyTuple_GET_ITEM(parameters, i);
|
||||
Py_XINCREF(current_param);
|
||||
Py_INCREF(current_param);
|
||||
} else if (PyList_CheckExact(parameters)) {
|
||||
current_param = PyList_GET_ITEM(parameters, i);
|
||||
current_param = PyList_GetItem(parameters, i);
|
||||
Py_XINCREF(current_param);
|
||||
} else {
|
||||
current_param = PySequence_GetItem(parameters, i);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue