summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorErlend Egeberg Aasland <erlend.aasland@protonmail.com>2022-06-08 10:43:54 (GMT)
committerGitHub <noreply@github.com>2022-06-08 10:43:54 (GMT)
commit875de61c296604f3a3a51e9d76355e0f1a24c6af (patch)
tree6546149ce452070ea70e9f09ad1ca8c06213c1b0 /Modules
parent5849af7a80166e9e82040e082f22772bd7cf3061 (diff)
downloadcpython-875de61c296604f3a3a51e9d76355e0f1a24c6af.zip
cpython-875de61c296604f3a3a51e9d76355e0f1a24c6af.tar.gz
cpython-875de61c296604f3a3a51e9d76355e0f1a24c6af.tar.bz2
gh-93421: Update sqlite3 cursor.rowcount only after SQLITE_DONE (#93526)
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_sqlite/cursor.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c
index c58def5..414584d 100644
--- a/Modules/_sqlite/cursor.c
+++ b/Modules/_sqlite/cursor.c
@@ -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) {