mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
bpo-42862: Use functools.lru_cache iso. _sqlite.Cache in sqlite3 module (GH-24203)
Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
This commit is contained in:
parent
f3fa63ec75
commit
f461a7fc3f
12 changed files with 77 additions and 438 deletions
|
|
@ -415,6 +415,14 @@ static int check_cursor(pysqlite_Cursor* cur)
|
|||
return pysqlite_check_thread(cur->connection) && pysqlite_check_connection(cur->connection);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
get_statement_from_cache(pysqlite_Cursor *self, PyObject *operation)
|
||||
{
|
||||
PyObject *args[] = { operation, };
|
||||
PyObject *cache = self->connection->statement_cache;
|
||||
return PyObject_Vectorcall(cache, args, 1, NULL);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
_pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation, PyObject* second_argument)
|
||||
{
|
||||
|
|
@ -423,7 +431,6 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
|
|||
PyObject* parameters = NULL;
|
||||
int i;
|
||||
int rc;
|
||||
PyObject* func_args;
|
||||
PyObject* result;
|
||||
int numcols;
|
||||
PyObject* column_name;
|
||||
|
|
@ -485,22 +492,12 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
|
|||
Py_SETREF(self->description, Py_None);
|
||||
self->rowcount = 0L;
|
||||
|
||||
func_args = PyTuple_New(1);
|
||||
if (!func_args) {
|
||||
goto error;
|
||||
}
|
||||
if (PyTuple_SetItem(func_args, 0, Py_NewRef(operation)) != 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (self->statement) {
|
||||
(void)pysqlite_statement_reset(self->statement);
|
||||
}
|
||||
|
||||
Py_XSETREF(self->statement,
|
||||
(pysqlite_Statement *)pysqlite_cache_get(self->connection->statement_cache, func_args));
|
||||
Py_DECREF(func_args);
|
||||
|
||||
PyObject *stmt = get_statement_from_cache(self, operation);
|
||||
Py_XSETREF(self->statement, (pysqlite_Statement *)stmt);
|
||||
if (!self->statement) {
|
||||
goto error;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue