mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
gh-93421: Update sqlite3 cursor.rowcount only after SQLITE_DONE (GH-93526)
(cherry picked from commit 875de61c29
)
Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@protonmail.com>
This commit is contained in:
parent
121ab58e03
commit
68aae80159
3 changed files with 22 additions and 8 deletions
|
@ -835,10 +835,9 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
|
|||
stmt_reset(self->statement);
|
||||
}
|
||||
|
||||
/* reset description and rowcount */
|
||||
/* reset description */
|
||||
Py_INCREF(Py_None);
|
||||
Py_SETREF(self->description, Py_None);
|
||||
self->rowcount = 0L;
|
||||
|
||||
if (self->statement) {
|
||||
(void)stmt_reset(self->statement);
|
||||
|
@ -867,6 +866,7 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
|
|||
|
||||
stmt_reset(self->statement);
|
||||
stmt_mark_dirty(self->statement);
|
||||
self->rowcount = self->statement->is_dml ? 0L : -1L;
|
||||
|
||||
/* We start a transaction implicitly before a DML statement.
|
||||
SELECT is the only exception. See #9924. */
|
||||
|
@ -944,18 +944,18 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
|
|||
}
|
||||
}
|
||||
|
||||
if (self->statement->is_dml) {
|
||||
self->rowcount += (long)sqlite3_changes(self->connection->db);
|
||||
} else {
|
||||
self->rowcount= -1L;
|
||||
}
|
||||
|
||||
if (rc == SQLITE_DONE && !multiple) {
|
||||
if (self->statement->is_dml) {
|
||||
self->rowcount = (long)sqlite3_changes(self->connection->db);
|
||||
}
|
||||
stmt_reset(self->statement);
|
||||
Py_CLEAR(self->statement);
|
||||
}
|
||||
|
||||
if (multiple) {
|
||||
if (self->statement->is_dml && rc == SQLITE_DONE) {
|
||||
self->rowcount += (long)sqlite3_changes(self->connection->db);
|
||||
}
|
||||
stmt_reset(self->statement);
|
||||
}
|
||||
Py_XDECREF(parameters);
|
||||
|
@ -1125,6 +1125,9 @@ pysqlite_cursor_iternext(pysqlite_Cursor *self)
|
|||
}
|
||||
int rc = stmt_step(stmt);
|
||||
if (rc == SQLITE_DONE) {
|
||||
if (self->statement->is_dml) {
|
||||
self->rowcount = (long)sqlite3_changes(self->connection->db);
|
||||
}
|
||||
(void)stmt_reset(self->statement);
|
||||
}
|
||||
else if (rc != SQLITE_ROW) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue