Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
bpo-44073: Use sqlite3_stmt_busy() to check statement status
  • Loading branch information
Erlend E. Aasland committed May 8, 2021
commit 952be7230233e983481a815cd9b88651ca95b986
1 change: 0 additions & 1 deletion Modules/_sqlite/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -1336,7 +1336,6 @@ pysqlite_connection_call(pysqlite_Connection *self, PyObject *args,
statement->db = NULL;
statement->st = NULL;
statement->sql = NULL;
statement->in_use = 0;
statement->in_weakreflist = NULL;

rc = pysqlite_statement_create(statement, self, sql);
Expand Down
5 changes: 1 addition & 4 deletions Modules/_sqlite/cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
goto error;
}

if (self->statement->in_use) {
if (sqlite3_stmt_busy(self->statement->st)) {
Py_SETREF(self->statement,
PyObject_New(pysqlite_Statement, pysqlite_StatementType));
if (!self->statement) {
Expand All @@ -499,7 +499,6 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
}

pysqlite_statement_reset(self->statement);
pysqlite_statement_mark_dirty(self->statement);

/* We start a transaction implicitly before a DML statement.
SELECT is the only exception. See #9924. */
Expand All @@ -519,8 +518,6 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
break;
}

pysqlite_statement_mark_dirty(self->statement);

pysqlite_statement_bind_parameters(self->statement, parameters);
if (PyErr_Occurred()) {
goto error;
Expand Down
14 changes: 1 addition & 13 deletions Modules/_sqlite/statement.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ int pysqlite_statement_create(pysqlite_Statement* self, pysqlite_Connection* con
const char* p;

self->st = NULL;
self->in_use = 0;

assert(PyUnicode_Check(sql));

Expand Down Expand Up @@ -339,8 +338,6 @@ int pysqlite_statement_finalize(pysqlite_Statement* self)
self->st = NULL;
}

self->in_use = 0;

return rc;
}

Expand All @@ -350,24 +347,15 @@ int pysqlite_statement_reset(pysqlite_Statement* self)

rc = SQLITE_OK;

if (self->in_use && self->st) {
if (self->st) {
Py_BEGIN_ALLOW_THREADS
rc = sqlite3_reset(self->st);
Py_END_ALLOW_THREADS

if (rc == SQLITE_OK) {
self->in_use = 0;
}
}

return rc;
}

void pysqlite_statement_mark_dirty(pysqlite_Statement* self)
{
self->in_use = 1;
}

static void
pysqlite_statement_dealloc(pysqlite_Statement *self)
{
Expand Down
2 changes: 0 additions & 2 deletions Modules/_sqlite/statement.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ typedef struct
sqlite3* db;
sqlite3_stmt* st;
PyObject* sql;
int in_use;
int is_dml;
PyObject* in_weakreflist; /* List of weak references */
} pysqlite_Statement;
Expand All @@ -52,7 +51,6 @@ void pysqlite_statement_bind_parameters(pysqlite_Statement* self, PyObject* para

int pysqlite_statement_finalize(pysqlite_Statement* self);
int pysqlite_statement_reset(pysqlite_Statement* self);
void pysqlite_statement_mark_dirty(pysqlite_Statement* self);

int pysqlite_statement_setup_types(PyObject *module);

Expand Down