summaryrefslogtreecommitdiffstats
path: root/Modules/_sqlite/statement.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2018-12-10 14:06:08 (GMT)
committerGitHub <noreply@github.com>2018-12-10 14:06:08 (GMT)
commitfc662ac332443a316a120fa5287c235dc4f8739b (patch)
tree3283170105c2e3b2dafa7233f4819cabab9fbb8d /Modules/_sqlite/statement.c
parentdffccc6b594951fc798973e521da205785823f0f (diff)
downloadcpython-fc662ac332443a316a120fa5287c235dc4f8739b.zip
cpython-fc662ac332443a316a120fa5287c235dc4f8739b.tar.gz
cpython-fc662ac332443a316a120fa5287c235dc4f8739b.tar.bz2
bpo-32788: Better error handling in sqlite3. (GH-3723)
Propagate unexpected errors (like MemoryError and KeyboardInterrupt) to user.
Diffstat (limited to 'Modules/_sqlite/statement.c')
-rw-r--r--Modules/_sqlite/statement.c34
1 files changed, 19 insertions, 15 deletions
diff --git a/Modules/_sqlite/statement.c b/Modules/_sqlite/statement.c
index 78033d8..575ac69 100644
--- a/Modules/_sqlite/statement.c
+++ b/Modules/_sqlite/statement.c
@@ -250,12 +250,10 @@ void pysqlite_statement_bind_parameters(pysqlite_Statement* self, PyObject* para
if (!_need_adapt(current_param)) {
adapted = current_param;
} else {
- adapted = pysqlite_microprotocols_adapt(current_param, (PyObject*)&pysqlite_PrepareProtocolType, NULL);
- if (adapted) {
- Py_DECREF(current_param);
- } else {
- PyErr_Clear();
- adapted = current_param;
+ adapted = pysqlite_microprotocols_adapt(current_param, (PyObject*)&pysqlite_PrepareProtocolType, current_param);
+ Py_DECREF(current_param);
+ if (!adapted) {
+ return;
}
}
@@ -272,6 +270,7 @@ void pysqlite_statement_bind_parameters(pysqlite_Statement* self, PyObject* para
} else if (PyDict_Check(parameters)) {
/* parameters passed as dictionary */
for (i = 1; i <= num_params_needed; i++) {
+ PyObject *binding_name_obj;
Py_BEGIN_ALLOW_THREADS
binding_name = sqlite3_bind_parameter_name(self->st, i);
Py_END_ALLOW_THREADS
@@ -281,26 +280,31 @@ void pysqlite_statement_bind_parameters(pysqlite_Statement* self, PyObject* para
}
binding_name++; /* skip first char (the colon) */
+ binding_name_obj = PyUnicode_FromString(binding_name);
+ if (!binding_name_obj) {
+ return;
+ }
if (PyDict_CheckExact(parameters)) {
- current_param = PyDict_GetItemString(parameters, binding_name);
+ current_param = PyDict_GetItemWithError(parameters, binding_name_obj);
Py_XINCREF(current_param);
} else {
- current_param = PyMapping_GetItemString(parameters, binding_name);
+ current_param = PyObject_GetItem(parameters, binding_name_obj);
}
+ Py_DECREF(binding_name_obj);
if (!current_param) {
- PyErr_Format(pysqlite_ProgrammingError, "You did not supply a value for binding %d.", i);
+ if (!PyErr_Occurred() || PyErr_ExceptionMatches(PyExc_LookupError)) {
+ PyErr_Format(pysqlite_ProgrammingError, "You did not supply a value for binding %d.", i);
+ }
return;
}
if (!_need_adapt(current_param)) {
adapted = current_param;
} else {
- adapted = pysqlite_microprotocols_adapt(current_param, (PyObject*)&pysqlite_PrepareProtocolType, NULL);
- if (adapted) {
- Py_DECREF(current_param);
- } else {
- PyErr_Clear();
- adapted = current_param;
+ adapted = pysqlite_microprotocols_adapt(current_param, (PyObject*)&pysqlite_PrepareProtocolType, current_param);
+ Py_DECREF(current_param);
+ if (!adapted) {
+ return;
}
}