summaryrefslogtreecommitdiffstats
path: root/Modules/_sqlite
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2020-09-17 07:57:07 (GMT)
committerGitHub <noreply@github.com>2020-09-17 07:57:07 (GMT)
commitf76a3889d1fc6c5514323866a047b642c6da4e9b (patch)
treee93c1ec627a4d318f53537de3c843e96136cbb0d /Modules/_sqlite
parenta9ba8ba9a71f3cb8d274c354ff67b6206abeb8ac (diff)
downloadcpython-f76a3889d1fc6c5514323866a047b642c6da4e9b.zip
cpython-f76a3889d1fc6c5514323866a047b642c6da4e9b.tar.gz
cpython-f76a3889d1fc6c5514323866a047b642c6da4e9b.tar.bz2
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 0b419b791077414bbc011a412698ebb362b63761) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Diffstat (limited to 'Modules/_sqlite')
-rw-r--r--Modules/_sqlite/statement.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/Modules/_sqlite/statement.c b/Modules/_sqlite/statement.c
index 9de8f9b..23c204e 100644
--- a/Modules/_sqlite/statement.c
+++ b/Modules/_sqlite/statement.c
@@ -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);