summaryrefslogtreecommitdiffstats
path: root/Modules/_sqlite/statement.c
diff options
context:
space:
mode:
authorErlend Egeberg Aasland <erlend.aasland@innova.no>2021-07-14 11:26:44 (GMT)
committerGitHub <noreply@github.com>2021-07-14 11:26:44 (GMT)
commit05162993fe62e7fa3acebdd0062586b9bf63d46a (patch)
tree136be9cca99943560f320c11e43d3fde38a41d10 /Modules/_sqlite/statement.c
parente5862f79c16e28f1ec51d179698739a9b2d8c1d2 (diff)
downloadcpython-05162993fe62e7fa3acebdd0062586b9bf63d46a.zip
cpython-05162993fe62e7fa3acebdd0062586b9bf63d46a.tar.gz
cpython-05162993fe62e7fa3acebdd0062586b9bf63d46a.tar.bz2
bpo-42064: Move `sqlite3` exceptions to global state, part 2 of 2 (GH-26884)
Automerge-Triggered-By: GH:encukou
Diffstat (limited to 'Modules/_sqlite/statement.c')
-rw-r--r--Modules/_sqlite/statement.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/Modules/_sqlite/statement.c b/Modules/_sqlite/statement.c
index 035023d..cca8616 100644
--- a/Modules/_sqlite/statement.c
+++ b/Modules/_sqlite/statement.c
@@ -56,8 +56,8 @@ pysqlite_statement_create(pysqlite_Connection *connection, PyObject *sql)
Py_ssize_t size;
const char *sql_cstr = PyUnicode_AsUTF8AndSize(sql, &size);
if (sql_cstr == NULL) {
- PyObject *exc = connection->Warning;
- PyErr_Format(exc, "SQL is of wrong type ('%s'). Must be string.",
+ PyErr_Format(connection->Warning,
+ "SQL is of wrong type ('%s'). Must be string.",
Py_TYPE(sql)->tp_name);
return NULL;
}
@@ -65,7 +65,8 @@ pysqlite_statement_create(pysqlite_Connection *connection, PyObject *sql)
sqlite3 *db = connection->db;
int max_length = sqlite3_limit(db, SQLITE_LIMIT_LENGTH, -1);
if (size >= max_length) {
- PyErr_SetString(pysqlite_DataError, "query string is too large");
+ PyErr_SetString(connection->DataError,
+ "query string is too large");
return NULL;
}
if (strlen(sql_cstr) != (size_t)size) {
@@ -87,8 +88,8 @@ pysqlite_statement_create(pysqlite_Connection *connection, PyObject *sql)
}
if (pysqlite_check_remaining_sql(tail)) {
- PyObject *exc = connection->Warning;
- PyErr_SetString(exc, "You can only execute one statement at a time.");
+ PyErr_SetString(connection->Warning,
+ "You can only execute one statement at a time.");
goto error;
}
@@ -250,7 +251,7 @@ void pysqlite_statement_bind_parameters(pysqlite_Statement* self, PyObject* para
}
}
if (num_params != num_params_needed) {
- PyErr_Format(pysqlite_ProgrammingError,
+ PyErr_Format(state->ProgrammingError,
"Incorrect number of bindings supplied. The current "
"statement uses %d, and there are %zd supplied.",
num_params_needed, num_params);
@@ -303,7 +304,9 @@ void pysqlite_statement_bind_parameters(pysqlite_Statement* self, PyObject* para
binding_name = sqlite3_bind_parameter_name(self->st, i);
Py_END_ALLOW_THREADS
if (!binding_name) {
- PyErr_Format(pysqlite_ProgrammingError, "Binding %d has no name, but you supplied a dictionary (which has only names).", i);
+ PyErr_Format(state->ProgrammingError,
+ "Binding %d has no name, but you supplied a "
+ "dictionary (which has only names).", i);
return;
}
@@ -321,7 +324,9 @@ void pysqlite_statement_bind_parameters(pysqlite_Statement* self, PyObject* para
Py_DECREF(binding_name_obj);
if (!current_param) {
if (!PyErr_Occurred() || PyErr_ExceptionMatches(PyExc_LookupError)) {
- PyErr_Format(pysqlite_ProgrammingError, "You did not supply a value for binding parameter :%s.", binding_name);
+ PyErr_Format(state->ProgrammingError,
+ "You did not supply a value for binding "
+ "parameter :%s.", binding_name);
}
return;
}