aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Modules/_sqlite/module.c
diff options
context:
space:
mode:
authorErlend Egeberg Aasland <erlend.aasland@innova.no>2021-06-23 14:56:40 +0200
committerGitHub <noreply@github.com>2021-06-23 05:56:40 -0700
commita50e28377bcf37121b55c2de70d95a5386c478f8 (patch)
tree10bd9512e7501dc798630a89770254be220d0905 /Modules/_sqlite/module.c
parent489699ca05bed5cfd10e847d8580840812b476cd (diff)
downloadcpython-a50e28377bcf37121b55c2de70d95a5386c478f8.tar.gz
cpython-a50e28377bcf37121b55c2de70d95a5386c478f8.zip
bpo-42064: Move `sqlite3` exceptions to global state, part 1 of 2 (GH-26745)
Also adds a test to verify the (borrowed) exceptions in `sqlite3.Connection`.
Diffstat (limited to 'Modules/_sqlite/module.c')
-rw-r--r--Modules/_sqlite/module.c36
1 files changed, 19 insertions, 17 deletions
diff --git a/Modules/_sqlite/module.c b/Modules/_sqlite/module.c
index 6adadf69216..2607c6ee3b4 100644
--- a/Modules/_sqlite/module.c
+++ b/Modules/_sqlite/module.c
@@ -43,11 +43,6 @@ module _sqlite3
/* static objects at module-level */
-PyObject *pysqlite_Error = NULL;
-PyObject *pysqlite_Warning = NULL;
-PyObject *pysqlite_InterfaceError = NULL;
-PyObject *pysqlite_DatabaseError = NULL;
-PyObject *pysqlite_InternalError = NULL;
PyObject *pysqlite_OperationalError = NULL;
PyObject *pysqlite_ProgrammingError = NULL;
PyObject *pysqlite_IntegrityError = NULL;
@@ -409,20 +404,27 @@ PyMODINIT_FUNC PyInit__sqlite3(void)
ADD_TYPE(module, state->RowType);
/*** Create DB-API Exception hierarchy */
- ADD_EXCEPTION(module, "Error", pysqlite_Error, PyExc_Exception);
- ADD_EXCEPTION(module, "Warning", pysqlite_Warning, PyExc_Exception);
+ ADD_EXCEPTION(module, "Error", state->Error, PyExc_Exception);
+ ADD_EXCEPTION(module, "Warning", state->Warning, PyExc_Exception);
/* Error subclasses */
- ADD_EXCEPTION(module, "InterfaceError", pysqlite_InterfaceError, pysqlite_Error);
- ADD_EXCEPTION(module, "DatabaseError", pysqlite_DatabaseError, pysqlite_Error);
-
- /* pysqlite_DatabaseError subclasses */
- ADD_EXCEPTION(module, "InternalError", pysqlite_InternalError, pysqlite_DatabaseError);
- ADD_EXCEPTION(module, "OperationalError", pysqlite_OperationalError, pysqlite_DatabaseError);
- ADD_EXCEPTION(module, "ProgrammingError", pysqlite_ProgrammingError, pysqlite_DatabaseError);
- ADD_EXCEPTION(module, "IntegrityError", pysqlite_IntegrityError, pysqlite_DatabaseError);
- ADD_EXCEPTION(module, "DataError", pysqlite_DataError, pysqlite_DatabaseError);
- ADD_EXCEPTION(module, "NotSupportedError", pysqlite_NotSupportedError, pysqlite_DatabaseError);
+ ADD_EXCEPTION(module, "InterfaceError", state->InterfaceError,
+ state->Error);
+ ADD_EXCEPTION(module, "DatabaseError", state->DatabaseError, state->Error);
+
+ /* DatabaseError subclasses */
+ ADD_EXCEPTION(module, "InternalError", state->InternalError,
+ state->DatabaseError);
+ ADD_EXCEPTION(module, "OperationalError", pysqlite_OperationalError,
+ state->DatabaseError);
+ ADD_EXCEPTION(module, "ProgrammingError", pysqlite_ProgrammingError,
+ state->DatabaseError);
+ ADD_EXCEPTION(module, "IntegrityError", pysqlite_IntegrityError,
+ state->DatabaseError);
+ ADD_EXCEPTION(module, "DataError", pysqlite_DataError,
+ state->DatabaseError);
+ ADD_EXCEPTION(module, "NotSupportedError", pysqlite_NotSupportedError,
+ state->DatabaseError);
/* Set integer constants */
if (add_integer_constants(module) < 0) {