Skip to content

Commit f5c85aa

Browse files
gh-88239: Use sqlite3_stmt_busy() to determine if statements are in use (#25984)
1 parent 71868a0 commit f5c85aa

File tree

3 files changed

+3
-18
lines changed

3 files changed

+3
-18
lines changed

Modules/_sqlite/cursor.c

+3-16
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,10 @@ stmt_reset(pysqlite_Statement *self)
130130
{
131131
int rc = SQLITE_OK;
132132

133-
if (self->in_use && self->st) {
133+
if (self->st != NULL) {
134134
Py_BEGIN_ALLOW_THREADS
135135
rc = sqlite3_reset(self->st);
136136
Py_END_ALLOW_THREADS
137-
138-
if (rc == SQLITE_OK) {
139-
self->in_use = 0;
140-
}
141137
}
142138

143139
return rc;
@@ -770,12 +766,6 @@ bind_parameters(pysqlite_state *state, pysqlite_Statement *self,
770766
}
771767
}
772768

773-
static inline void
774-
stmt_mark_dirty(pysqlite_Statement *self)
775-
{
776-
self->in_use = 1;
777-
}
778-
779769
PyObject *
780770
_pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation, PyObject* second_argument)
781771
{
@@ -852,16 +842,15 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
852842
goto error;
853843
}
854844

855-
if (self->statement->in_use) {
845+
if (sqlite3_stmt_busy(self->statement->st)) {
856846
Py_SETREF(self->statement,
857847
pysqlite_statement_create(self->connection, operation));
858848
if (self->statement == NULL) {
859849
goto error;
860850
}
861851
}
862852

863-
stmt_reset(self->statement);
864-
stmt_mark_dirty(self->statement);
853+
(void)stmt_reset(self->statement);
865854
self->rowcount = self->statement->is_dml ? 0L : -1L;
866855

867856
/* We start a transaction implicitly before a DML statement.
@@ -882,8 +871,6 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
882871
break;
883872
}
884873

885-
stmt_mark_dirty(self->statement);
886-
887874
bind_parameters(state, self->statement, parameters);
888875
if (PyErr_Occurred()) {
889876
goto error;

Modules/_sqlite/statement.c

-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ pysqlite_statement_create(pysqlite_Connection *connection, PyObject *sql)
8888
}
8989

9090
self->st = stmt;
91-
self->in_use = 0;
9291
self->is_dml = is_dml;
9392

9493
PyObject_GC_Track(self);

Modules/_sqlite/statement.h

-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ typedef struct
3333
{
3434
PyObject_HEAD
3535
sqlite3_stmt* st;
36-
int in_use;
3736
int is_dml;
3837
} pysqlite_Statement;
3938

0 commit comments

Comments
 (0)