Skip to content

Commit 4cf1a82

Browse files
author
Erlend E. Aasland
committed
Move sqlite3.InterfaceError to global state
1 parent 814df2f commit 4cf1a82

File tree

5 files changed

+13
-8
lines changed

5 files changed

+13
-8
lines changed

Modules/_sqlite/connection.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ pysqlite_connection_init(pysqlite_Connection *self, PyObject *args,
191191
pysqlite_state *state = pysqlite_get_state(NULL);
192192
self->Warning = state->Warning;
193193
self->Error = state->Error;
194-
self->InterfaceError = pysqlite_InterfaceError;
194+
self->InterfaceError = state->InterfaceError;
195195
self->DatabaseError = pysqlite_DatabaseError;
196196
self->DataError = pysqlite_DataError;
197197
self->OperationalError = pysqlite_OperationalError;

Modules/_sqlite/cursor.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,8 @@ _pysqlite_fetch_one_row(pysqlite_Cursor* self)
272272
PyObject* error_msg;
273273

274274
if (self->reset) {
275-
PyErr_SetString(pysqlite_InterfaceError, errmsg_fetch_across_rollback);
275+
pysqlite_state *state = pysqlite_get_state(NULL);
276+
PyErr_SetString(state->InterfaceError, errmsg_fetch_across_rollback);
276277
return NULL;
277278
}
278279

@@ -822,7 +823,8 @@ pysqlite_cursor_iternext(pysqlite_Cursor *self)
822823
}
823824

824825
if (self->reset) {
825-
PyErr_SetString(pysqlite_InterfaceError, errmsg_fetch_across_rollback);
826+
pysqlite_state *state = pysqlite_get_state(NULL);
827+
PyErr_SetString(state->InterfaceError, errmsg_fetch_across_rollback);
826828
return NULL;
827829
}
828830

Modules/_sqlite/module.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ module _sqlite3
4343

4444
/* static objects at module-level */
4545

46-
PyObject *pysqlite_InterfaceError = NULL;
4746
PyObject *pysqlite_DatabaseError = NULL;
4847
PyObject *pysqlite_InternalError = NULL;
4948
PyObject *pysqlite_OperationalError = NULL;
@@ -413,7 +412,7 @@ PyMODINIT_FUNC PyInit__sqlite3(void)
413412
ADD_EXCEPTION(module, "Warning", state->Warning, PyExc_Exception);
414413

415414
/* Error subclasses */
416-
ADD_EXCEPTION(module, "InterfaceError", pysqlite_InterfaceError,
415+
ADD_EXCEPTION(module, "InterfaceError", state->InterfaceError,
417416
state->Error);
418417
ADD_EXCEPTION(module, "DatabaseError", pysqlite_DatabaseError,
419418
state->Error);

Modules/_sqlite/module.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
typedef struct {
3333
PyObject *Error;
34+
PyObject *InterfaceError;
3435
PyObject *Warning;
3536
PyObject *lru_cache;
3637
PyTypeObject *ConnectionType;
@@ -48,7 +49,6 @@ pysqlite_get_state(PyObject *Py_UNUSED(module))
4849
return &pysqlite_global_state;
4950
}
5051

51-
extern PyObject* pysqlite_InterfaceError;
5252
extern PyObject* pysqlite_DatabaseError;
5353
extern PyObject* pysqlite_InternalError;
5454
extern PyObject* pysqlite_OperationalError;

Modules/_sqlite/statement.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,9 @@ void pysqlite_statement_bind_parameters(pysqlite_Statement* self, PyObject* para
288288

289289
if (rc != SQLITE_OK) {
290290
if (!PyErr_Occurred()) {
291-
PyErr_Format(pysqlite_InterfaceError, "Error binding parameter %d - probably unsupported type.", i);
291+
PyErr_Format(state->InterfaceError,
292+
"Error binding parameter %d - "
293+
"probably unsupported type.", i);
292294
}
293295
return;
294296
}
@@ -342,7 +344,9 @@ void pysqlite_statement_bind_parameters(pysqlite_Statement* self, PyObject* para
342344

343345
if (rc != SQLITE_OK) {
344346
if (!PyErr_Occurred()) {
345-
PyErr_Format(pysqlite_InterfaceError, "Error binding parameter :%s - probably unsupported type.", binding_name);
347+
PyErr_Format(state->InterfaceError,
348+
"Error binding parameter :%s - "
349+
"probably unsupported type.", binding_name);
346350
}
347351
return;
348352
}

0 commit comments

Comments
 (0)