]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-88239: Use sqlite3_stmt_busy() to determine if statements are in use (#25984)
authorErlend Egeberg Aasland <erlend.aasland@protonmail.com>
Mon, 27 Jun 2022 07:58:56 +0000 (09:58 +0200)
committerGitHub <noreply@github.com>
Mon, 27 Jun 2022 07:58:56 +0000 (09:58 +0200)
Modules/_sqlite/cursor.c
Modules/_sqlite/statement.c
Modules/_sqlite/statement.h

index 8d9f20da530b232fc7a35c30a37c701a9b9afc67..cbf4718365fee649c207cac7bb439be448f2985c 100644 (file)
@@ -130,14 +130,10 @@ stmt_reset(pysqlite_Statement *self)
 {
     int rc = SQLITE_OK;
 
-    if (self->in_use && self->st) {
+    if (self->st != NULL) {
         Py_BEGIN_ALLOW_THREADS
         rc = sqlite3_reset(self->st);
         Py_END_ALLOW_THREADS
-
-        if (rc == SQLITE_OK) {
-            self->in_use = 0;
-        }
     }
 
     return rc;
@@ -770,12 +766,6 @@ bind_parameters(pysqlite_state *state, pysqlite_Statement *self,
     }
 }
 
-static inline void
-stmt_mark_dirty(pysqlite_Statement *self)
-{
-    self->in_use = 1;
-}
-
 PyObject *
 _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation, PyObject* second_argument)
 {
@@ -852,7 +842,7 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
         goto error;
     }
 
-    if (self->statement->in_use) {
+    if (sqlite3_stmt_busy(self->statement->st)) {
         Py_SETREF(self->statement,
                   pysqlite_statement_create(self->connection, operation));
         if (self->statement == NULL) {
@@ -860,8 +850,7 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
         }
     }
 
-    stmt_reset(self->statement);
-    stmt_mark_dirty(self->statement);
+    (void)stmt_reset(self->statement);
     self->rowcount = self->statement->is_dml ? 0L : -1L;
 
     /* We start a transaction implicitly before a DML statement.
@@ -882,8 +871,6 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
             break;
         }
 
-        stmt_mark_dirty(self->statement);
-
         bind_parameters(state, self->statement, parameters);
         if (PyErr_Occurred()) {
             goto error;
index aee460747b45f4eace31bb21d5999ed125108848..229bfc3b5041650113edeee73bc7d08a5afc44c0 100644 (file)
@@ -88,7 +88,6 @@ pysqlite_statement_create(pysqlite_Connection *connection, PyObject *sql)
     }
 
     self->st = stmt;
-    self->in_use = 0;
     self->is_dml = is_dml;
 
     PyObject_GC_Track(self);
index 5e61227424bafaf0b7587860a9153313e09eb26d..11a6464b1a1c2b7477641f8f0fc9abd349c9acec 100644 (file)
@@ -33,7 +33,6 @@ typedef struct
 {
     PyObject_HEAD
     sqlite3_stmt* st;
-    int in_use;
     int is_dml;
 } pysqlite_Statement;