Skip to content

Commit e6e4973

Browse files
author
Erlend E. Aasland
committed
If possible, avoid resetting unused statements
1 parent 2f8cb23 commit e6e4973

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

Modules/_sqlite/statement.c

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -362,20 +362,28 @@ pysqlite_statement_bind_parameters(pysqlite_state *state,
362362

363363
int pysqlite_statement_reset(pysqlite_Statement* self)
364364
{
365-
int rc;
365+
sqlite3_stmt *stmt = self->st;
366+
if (stmt == NULL || self->in_use == 0) {
367+
return SQLITE_OK;
368+
}
366369

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

369-
if (self->in_use && self->st) {
370-
Py_BEGIN_ALLOW_THREADS
371-
rc = sqlite3_reset(self->st);
372-
Py_END_ALLOW_THREADS
379+
int rc;
380+
Py_BEGIN_ALLOW_THREADS
381+
rc = sqlite3_reset(self->st);
382+
Py_END_ALLOW_THREADS
373383

374-
if (rc == SQLITE_OK) {
375-
self->in_use = 0;
376-
}
384+
if (rc == SQLITE_OK) {
385+
self->in_use = 0;
377386
}
378-
379387
return rc;
380388
}
381389

0 commit comments

Comments
 (0)