Skip to content

Commit e82adb8

Browse files
pythongh-79579: Update sqlite3.Cursor.rowcount for all datamodifying queries
1 parent 86a5e22 commit e82adb8

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

Lib/test/test_sqlite3/test_dbapi.py

+7
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,13 @@ def test_rowcount_executemany(self):
887887
self.cu.executemany("insert into test(name) values (?)", [(1,), (2,), (3,)])
888888
self.assertEqual(self.cu.rowcount, 3)
889889

890+
def test_rowcount_prefixed_with_comment(self):
891+
# gh-79579: rowcount is updated even if query is prefixed with comments
892+
self.cu.execute("/* foo */ insert into test(name) values (?)", ('foo',))
893+
self.assertEqual(self.cu.rowcount, 1)
894+
self.cu.execute("/* bar */ update test set name='bar' where name='foo'")
895+
self.assertEqual(self.cu.rowcount, 2)
896+
890897
def test_total_changes(self):
891898
self.cu.execute("insert into test(name) values ('foo')")
892899
self.cu.execute("insert into test(name) values ('foo')")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
:data:`sqlite3.Cursor.rowcount` is now correctly updated for all datamodifying
2+
SQL queries. Patch by Erlend E. Aasland.

Modules/_sqlite/cursor.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,7 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
944944
}
945945
}
946946

947-
if (self->statement->is_dml) {
947+
if (!sqlite3_stmt_readonly(self->statement->st)) {
948948
self->rowcount += (long)sqlite3_changes(self->connection->db);
949949
} else {
950950
self->rowcount= -1L;

0 commit comments

Comments
 (0)