diff options
author | Erlend Egeberg Aasland <erlend.aasland@innova.no> | 2021-07-29 11:21:45 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-29 02:21:45 -0700 |
commit | d542742128b634264d5b6796297613975211b43b (patch) | |
tree | e541d59593fe7df7bd96367d60ac96b1e7e76606 /Modules/_sqlite/statement.c | |
parent | 47fd4726a2ce8599cc397ddeae40f70eb471e868 (diff) | |
download | cpython-d542742128b634264d5b6796297613975211b43b.tar.gz cpython-d542742128b634264d5b6796297613975211b43b.zip |
bpo-42064: Optimise `sqlite3` state access, part 1 (GH-27273)
Prepare for module state:
- Add "get state by defining class" and "get state by module def" stubs
- Add AC defining class when needed
- Add state pointer to connection context
- Pass state as argument to utility functions
Automerge-Triggered-By: GH:encukou
Diffstat (limited to 'Modules/_sqlite/statement.c')
-rw-r--r-- | Modules/_sqlite/statement.c | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/Modules/_sqlite/statement.c b/Modules/_sqlite/statement.c index 8add50960f8..983df2d50c9 100644 --- a/Modules/_sqlite/statement.c +++ b/Modules/_sqlite/statement.c @@ -51,7 +51,7 @@ typedef enum { pysqlite_Statement * pysqlite_statement_create(pysqlite_Connection *connection, PyObject *sql) { - pysqlite_state *state = pysqlite_get_state(NULL); + pysqlite_state *state = connection->state; assert(PyUnicode_Check(sql)); Py_ssize_t size; const char *sql_cstr = PyUnicode_AsUTF8AndSize(sql, &size); @@ -83,7 +83,7 @@ pysqlite_statement_create(pysqlite_Connection *connection, PyObject *sql) Py_END_ALLOW_THREADS if (rc != SQLITE_OK) { - _pysqlite_seterror(db); + _pysqlite_seterror(state, db); return NULL; } @@ -209,9 +209,9 @@ final: } /* returns 0 if the object is one of Python's internal ones that don't need to be adapted */ -static int _need_adapt(PyObject* obj) +static int +_need_adapt(pysqlite_state *state, PyObject *obj) { - pysqlite_state *state = pysqlite_get_state(NULL); if (state->BaseTypeAdapted) { return 1; } @@ -224,9 +224,11 @@ static int _need_adapt(PyObject* obj) } } -void pysqlite_statement_bind_parameters(pysqlite_Statement* self, PyObject* parameters) +void +pysqlite_statement_bind_parameters(pysqlite_state *state, + pysqlite_Statement *self, + PyObject *parameters) { - pysqlite_state *state = pysqlite_get_state(NULL); PyObject* current_param; PyObject* adapted; const char* binding_name; @@ -272,11 +274,11 @@ void pysqlite_statement_bind_parameters(pysqlite_Statement* self, PyObject* para return; } - if (!_need_adapt(current_param)) { + if (!_need_adapt(state, current_param)) { adapted = current_param; } else { PyObject *protocol = (PyObject *)state->PrepareProtocolType; - adapted = pysqlite_microprotocols_adapt(current_param, + adapted = pysqlite_microprotocols_adapt(state, current_param, protocol, current_param); Py_DECREF(current_param); @@ -332,11 +334,11 @@ void pysqlite_statement_bind_parameters(pysqlite_Statement* self, PyObject* para return; } - if (!_need_adapt(current_param)) { + if (!_need_adapt(state, current_param)) { adapted = current_param; } else { PyObject *protocol = (PyObject *)state->PrepareProtocolType; - adapted = pysqlite_microprotocols_adapt(current_param, + adapted = pysqlite_microprotocols_adapt(state, current_param, protocol, current_param); Py_DECREF(current_param); |