bpo-44958: Only reset sqlite3 statements when needed (GH-27844)

This commit is contained in:
Erlend Egeberg Aasland 2021-09-21 13:20:34 +02:00 committed by GitHub
parent debd804037
commit 050d103595
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 84 additions and 48 deletions

View file

@ -360,23 +360,31 @@ pysqlite_statement_bind_parameters(pysqlite_state *state,
}
}
int pysqlite_statement_reset(pysqlite_Statement* self)
void
pysqlite_statement_reset(pysqlite_Statement *self)
{
int rc;
rc = SQLITE_OK;
if (self->in_use && self->st) {
Py_BEGIN_ALLOW_THREADS
rc = sqlite3_reset(self->st);
Py_END_ALLOW_THREADS
if (rc == SQLITE_OK) {
self->in_use = 0;
}
sqlite3_stmt *stmt = self->st;
if (stmt == NULL || self->in_use == 0) {
return;
}
return rc;
#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;
}
#endif
int rc;
Py_BEGIN_ALLOW_THREADS
rc = sqlite3_reset(stmt);
Py_END_ALLOW_THREADS
if (rc == SQLITE_OK) {
self->in_use = 0;
}
}
void pysqlite_statement_mark_dirty(pysqlite_Statement* self)