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`.
This commit is contained in:
Erlend Egeberg Aasland 2021-06-23 14:56:40 +02:00 committed by GitHub
parent 489699ca05
commit a50e28377b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 66 additions and 48 deletions

View file

@ -43,6 +43,7 @@ pysqlite_step(sqlite3_stmt *statement)
int
_pysqlite_seterror(sqlite3 *db)
{
pysqlite_state *state = pysqlite_get_state(NULL);
int errorcode = sqlite3_errcode(db);
switch (errorcode)
@ -52,7 +53,7 @@ _pysqlite_seterror(sqlite3 *db)
break;
case SQLITE_INTERNAL:
case SQLITE_NOTFOUND:
PyErr_SetString(pysqlite_InternalError, sqlite3_errmsg(db));
PyErr_SetString(state->InternalError, sqlite3_errmsg(db));
break;
case SQLITE_NOMEM:
(void)PyErr_NoMemory();
@ -73,7 +74,7 @@ _pysqlite_seterror(sqlite3 *db)
PyErr_SetString(pysqlite_OperationalError, sqlite3_errmsg(db));
break;
case SQLITE_CORRUPT:
PyErr_SetString(pysqlite_DatabaseError, sqlite3_errmsg(db));
PyErr_SetString(state->DatabaseError, sqlite3_errmsg(db));
break;
case SQLITE_TOOBIG:
PyErr_SetString(pysqlite_DataError, sqlite3_errmsg(db));
@ -86,7 +87,7 @@ _pysqlite_seterror(sqlite3 *db)
PyErr_SetString(pysqlite_ProgrammingError, sqlite3_errmsg(db));
break;
default:
PyErr_SetString(pysqlite_DatabaseError, sqlite3_errmsg(db));
PyErr_SetString(state->DatabaseError, sqlite3_errmsg(db));
break;
}