diff options
Diffstat (limited to 'Modules/_sqlite/connection.c')
-rw-r--r-- | Modules/_sqlite/connection.c | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c index 85b666a419..a95b75a0fe 100644 --- a/Modules/_sqlite/connection.c +++ b/Modules/_sqlite/connection.c @@ -66,8 +66,8 @@ new_statement_cache(pysqlite_Connection *self, int maxsize) if (args[0] == NULL) { return NULL; } - pysqlite_state *state = pysqlite_get_state(NULL); - PyObject *inner = PyObject_Vectorcall(state->lru_cache, args, 1, NULL); + PyObject *lru_cache = self->state->lru_cache; + PyObject *inner = PyObject_Vectorcall(lru_cache, args, 1, NULL); Py_DECREF(args[0]); if (inner == NULL) { return NULL; @@ -106,6 +106,9 @@ pysqlite_connection_init_impl(pysqlite_Connection *self, return -1; } + pysqlite_state *state = pysqlite_get_state_by_type(Py_TYPE(self)); + self->state = state; + const char *database = PyBytes_AsString(database_obj); self->initialized = 1; @@ -131,7 +134,7 @@ pysqlite_connection_init_impl(pysqlite_Connection *self, Py_DECREF(database_obj); // needed bco. the AC FSConverter if (rc != SQLITE_OK) { - _pysqlite_seterror(self->db); + _pysqlite_seterror(state, self->db); return -1; } @@ -177,7 +180,6 @@ pysqlite_connection_init_impl(pysqlite_Connection *self, self->function_pinboard_progress_handler = NULL; self->function_pinboard_authorizer_cb = NULL; - pysqlite_state *state = pysqlite_get_state(NULL); self->Warning = state->Warning; self->Error = state->Error; self->InterfaceError = state->InterfaceError; @@ -330,15 +332,14 @@ pysqlite_connection_cursor_impl(pysqlite_Connection *self, PyObject *factory) return NULL; } - pysqlite_state *state = pysqlite_get_state(NULL); if (factory == NULL) { - factory = (PyObject *)state->CursorType; + factory = (PyObject *)self->state->CursorType; } cursor = PyObject_CallOneArg(factory, (PyObject *)self); if (cursor == NULL) return NULL; - if (!PyObject_TypeCheck(cursor, state->CursorType)) { + if (!PyObject_TypeCheck(cursor, self->state->CursorType)) { PyErr_Format(PyExc_TypeError, "factory must return a cursor, not %.100s", Py_TYPE(cursor)->tp_name); @@ -383,15 +384,15 @@ pysqlite_connection_close_impl(pysqlite_Connection *self) */ int pysqlite_check_connection(pysqlite_Connection* con) { - pysqlite_state *state = pysqlite_get_state(NULL); if (!con->initialized) { + pysqlite_state *state = pysqlite_get_state_by_type(Py_TYPE(con)); PyErr_SetString(state->ProgrammingError, "Base Connection.__init__ not called."); return 0; } if (!con->db) { - PyErr_SetString(state->ProgrammingError, + PyErr_SetString(con->state->ProgrammingError, "Cannot operate on a closed database."); return 0; } else { @@ -422,20 +423,20 @@ pysqlite_connection_commit_impl(pysqlite_Connection *self) rc = sqlite3_prepare_v2(self->db, "COMMIT", 7, &statement, NULL); Py_END_ALLOW_THREADS if (rc != SQLITE_OK) { - _pysqlite_seterror(self->db); + _pysqlite_seterror(self->state, self->db); goto error; } rc = pysqlite_step(statement); if (rc != SQLITE_DONE) { - _pysqlite_seterror(self->db); + _pysqlite_seterror(self->state, self->db); } Py_BEGIN_ALLOW_THREADS rc = sqlite3_finalize(statement); Py_END_ALLOW_THREADS if (rc != SQLITE_OK && !PyErr_Occurred()) { - _pysqlite_seterror(self->db); + _pysqlite_seterror(self->state, self->db); } } @@ -472,20 +473,20 @@ pysqlite_connection_rollback_impl(pysqlite_Connection *self) rc = sqlite3_prepare_v2(self->db, "ROLLBACK", 9, &statement, NULL); Py_END_ALLOW_THREADS if (rc != SQLITE_OK) { - _pysqlite_seterror(self->db); + _pysqlite_seterror(self->state, self->db); goto error; } rc = pysqlite_step(statement); if (rc != SQLITE_DONE) { - _pysqlite_seterror(self->db); + _pysqlite_seterror(self->state, self->db); } Py_BEGIN_ALLOW_THREADS rc = sqlite3_finalize(statement); Py_END_ALLOW_THREADS if (rc != SQLITE_OK && !PyErr_Occurred()) { - _pysqlite_seterror(self->db); + _pysqlite_seterror(self->state, self->db); } } @@ -1672,7 +1673,7 @@ pysqlite_connection_backup_impl(pysqlite_Connection *self, Py_END_ALLOW_THREADS if (bck_handle == NULL) { - _pysqlite_seterror(bck_conn); + _pysqlite_seterror(self->state, bck_conn); return NULL; } @@ -1710,7 +1711,7 @@ pysqlite_connection_backup_impl(pysqlite_Connection *self, Py_END_ALLOW_THREADS if (rc != SQLITE_OK) { - _pysqlite_seterror(bck_conn); + _pysqlite_seterror(self->state, bck_conn); return NULL; } @@ -1762,7 +1763,7 @@ pysqlite_connection_create_collation_impl(pysqlite_Connection *self, if (callable != Py_None) { Py_DECREF(callable); } - _pysqlite_seterror(self->db); + _pysqlite_seterror(self->state, self->db); return NULL; } |