aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Modules/_sqlite/statement.c
diff options
context:
space:
mode:
authorErlend Egeberg Aasland <erlend.aasland@innova.no>2021-09-21 13:20:34 +0200
committerGitHub <noreply@github.com>2021-09-21 12:20:34 +0100
commit050d1035957379d70e8601e6f5636637716a264b (patch)
treee6d21a1cc20b46585e1da7433556f8ce5107b594 /Modules/_sqlite/statement.c
parentdebd80403721b00423680328d6adf160a28fbff4 (diff)
downloadcpython-050d1035957379d70e8601e6f5636637716a264b.tar.gz
cpython-050d1035957379d70e8601e6f5636637716a264b.zip
bpo-44958: Only reset `sqlite3` statements when needed (GH-27844)
Diffstat (limited to 'Modules/_sqlite/statement.c')
-rw-r--r--Modules/_sqlite/statement.c32
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)