diff options
Diffstat (limited to 'Modules/_sqlite/statement.c')
-rw-r--r-- | Modules/_sqlite/statement.c | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/Modules/_sqlite/statement.c b/Modules/_sqlite/statement.c index b20c91da317..3016fe5bb45 100644 --- a/Modules/_sqlite/statement.c +++ b/Modules/_sqlite/statement.c @@ -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; + sqlite3_stmt *stmt = self->st; + if (stmt == NULL || self->in_use == 0) { + return; + } - 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; + } +#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(stmt); + Py_END_ALLOW_THREADS - if (rc == SQLITE_OK) { - self->in_use = 0; - } + if (rc == SQLITE_OK) { + self->in_use = 0; } - - return rc; } void pysqlite_statement_mark_dirty(pysqlite_Statement* self) |