Skip to content
Merged
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
Prev Previous commit
Next Next commit
If possible, avoid resetting unused statements
  • Loading branch information
Erlend E. Aasland committed Aug 20, 2021
commit e6e4973f08cc77fbdd6abf955d6e42104f6970f5
28 changes: 18 additions & 10 deletions Modules/_sqlite/statement.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,20 +362,28 @@ pysqlite_statement_bind_parameters(pysqlite_state *state,

int pysqlite_statement_reset(pysqlite_Statement* self)
{
int rc;
sqlite3_stmt *stmt = self->st;
if (stmt == NULL || self->in_use == 0) {
return SQLITE_OK;
}

rc = SQLITE_OK;
#if SQLITE_VERSION_NUMBER > 3020000
/* Check if the statement has been run (that is, sqlite3_step() has been
* called at least once). Third parameter is non-zero in order to reset the
* run count. */
if (sqlite3_stmt_status(stmt, SQLITE_STMTSTATUS_RUN, 1) == 0) {
return SQLITE_OK;
}
#endif

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

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

return rc;
}

Expand Down