aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Modules/_sqlite/cursor.c
diff options
context:
space:
mode:
authorErlend Egeberg Aasland <erlend.aasland@innova.no>2021-07-14 13:26:44 +0200
committerGitHub <noreply@github.com>2021-07-14 04:26:44 -0700
commit05162993fe62e7fa3acebdd0062586b9bf63d46a (patch)
tree136be9cca99943560f320c11e43d3fde38a41d10 /Modules/_sqlite/cursor.c
parente5862f79c16e28f1ec51d179698739a9b2d8c1d2 (diff)
downloadcpython-05162993fe62e7fa3acebdd0062586b9bf63d46a.tar.gz
cpython-05162993fe62e7fa3acebdd0062586b9bf63d46a.zip
bpo-42064: Move `sqlite3` exceptions to global state, part 2 of 2 (GH-26884)
Automerge-Triggered-By: GH:encukou
Diffstat (limited to 'Modules/_sqlite/cursor.c')
-rw-r--r--Modules/_sqlite/cursor.c30
1 files changed, 21 insertions, 9 deletions
diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c
index 451742b3ecd..0f821c7e8c3 100644
--- a/Modules/_sqlite/cursor.c
+++ b/Modules/_sqlite/cursor.c
@@ -351,10 +351,12 @@ _pysqlite_fetch_one_row(pysqlite_Cursor* self)
PyOS_snprintf(buf, sizeof(buf) - 1, "Could not decode to UTF-8 column '%s' with text '%s'",
colname , text);
error_msg = PyUnicode_Decode(buf, strlen(buf), "ascii", "replace");
+
+ PyObject *exc = self->connection->OperationalError;
if (!error_msg) {
- PyErr_SetString(pysqlite_OperationalError, "Could not decode to UTF-8");
+ PyErr_SetString(exc, "Could not decode to UTF-8");
} else {
- PyErr_SetObject(pysqlite_OperationalError, error_msg);
+ PyErr_SetObject(exc, error_msg);
Py_DECREF(error_msg);
}
}
@@ -401,18 +403,23 @@ error:
*/
static int check_cursor(pysqlite_Cursor* cur)
{
+ pysqlite_state *state = pysqlite_get_state(NULL);
+
if (!cur->initialized) {
- PyErr_SetString(pysqlite_ProgrammingError, "Base Cursor.__init__ not called.");
+ PyErr_SetString(state->ProgrammingError,
+ "Base Cursor.__init__ not called.");
return 0;
}
if (cur->closed) {
- PyErr_SetString(pysqlite_ProgrammingError, "Cannot operate on a closed cursor.");
+ PyErr_SetString(state->ProgrammingError,
+ "Cannot operate on a closed cursor.");
return 0;
}
if (cur->locked) {
- PyErr_SetString(pysqlite_ProgrammingError, "Recursive use of cursors not allowed.");
+ PyErr_SetString(state->ProgrammingError,
+ "Recursive use of cursors not allowed.");
return 0;
}
@@ -588,7 +595,8 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
}
if (pysqlite_build_row_cast_map(self) != 0) {
- _PyErr_FormatFromCause(pysqlite_OperationalError, "Error while building row_cast_map");
+ _PyErr_FormatFromCause(self->connection->OperationalError,
+ "Error while building row_cast_map");
goto error;
}
@@ -641,7 +649,9 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
if (rc == SQLITE_ROW) {
if (multiple) {
- PyErr_SetString(pysqlite_ProgrammingError, "executemany() can only execute DML statements.");
+ PyErr_SetString(self->connection->ProgrammingError,
+ "executemany() can only execute DML "
+ "statements.");
goto error;
}
@@ -745,7 +755,8 @@ pysqlite_cursor_executescript(pysqlite_Cursor *self, PyObject *script_obj)
int max_length = sqlite3_limit(self->connection->db,
SQLITE_LIMIT_LENGTH, -1);
if (sql_len >= max_length) {
- PyErr_SetString(pysqlite_DataError, "query string is too large");
+ PyErr_SetString(self->connection->DataError,
+ "query string is too large");
return NULL;
}
} else {
@@ -1018,7 +1029,8 @@ pysqlite_cursor_close_impl(pysqlite_Cursor *self)
/*[clinic end generated code: output=b6055e4ec6fe63b6 input=08b36552dbb9a986]*/
{
if (!self->connection) {
- PyErr_SetString(pysqlite_ProgrammingError,
+ pysqlite_state *state = pysqlite_get_state(NULL);
+ PyErr_SetString(state->ProgrammingError,
"Base Cursor.__init__ not called.");
return NULL;
}