mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
bpo-44958: Only reset sqlite3
statements when needed (GH-27844)
This commit is contained in:
parent
debd804037
commit
050d103595
4 changed files with 84 additions and 48 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue