@@ -835,10 +835,9 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
835
835
stmt_reset (self -> statement );
836
836
}
837
837
838
- /* reset description and rowcount */
838
+ /* reset description */
839
839
Py_INCREF (Py_None );
840
840
Py_SETREF (self -> description , Py_None );
841
- self -> rowcount = 0L ;
842
841
843
842
if (self -> statement ) {
844
843
(void )stmt_reset (self -> statement );
@@ -867,6 +866,7 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
867
866
868
867
stmt_reset (self -> statement );
869
868
stmt_mark_dirty (self -> statement );
869
+ self -> rowcount = self -> statement -> is_dml ? 0L : -1L ;
870
870
871
871
/* We start a transaction implicitly before a DML statement.
872
872
SELECT is the only exception. See #9924. */
@@ -944,18 +944,18 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
944
944
}
945
945
}
946
946
947
- if (self -> statement -> is_dml ) {
948
- self -> rowcount += (long )sqlite3_changes (self -> connection -> db );
949
- } else {
950
- self -> rowcount = -1L ;
951
- }
952
-
953
947
if (rc == SQLITE_DONE && !multiple ) {
948
+ if (self -> statement -> is_dml ) {
949
+ self -> rowcount = (long )sqlite3_changes (self -> connection -> db );
950
+ }
954
951
stmt_reset (self -> statement );
955
952
Py_CLEAR (self -> statement );
956
953
}
957
954
958
955
if (multiple ) {
956
+ if (self -> statement -> is_dml && rc == SQLITE_DONE ) {
957
+ self -> rowcount += (long )sqlite3_changes (self -> connection -> db );
958
+ }
959
959
stmt_reset (self -> statement );
960
960
}
961
961
Py_XDECREF (parameters );
@@ -1125,6 +1125,9 @@ pysqlite_cursor_iternext(pysqlite_Cursor *self)
1125
1125
}
1126
1126
int rc = stmt_step (stmt );
1127
1127
if (rc == SQLITE_DONE ) {
1128
+ if (self -> statement -> is_dml ) {
1129
+ self -> rowcount = (long )sqlite3_changes (self -> connection -> db );
1130
+ }
1128
1131
(void )stmt_reset (self -> statement );
1129
1132
}
1130
1133
else if (rc != SQLITE_ROW ) {
0 commit comments