@@ -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,13 +944,14 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
944
944
}
945
945
}
946
946
947
- if (self -> statement -> is_dml ) {
947
+ if (self -> statement -> is_dml && multiple ) {
948
948
self -> rowcount += (long )sqlite3_changes (self -> connection -> db );
949
- } else {
950
- self -> rowcount = -1L ;
951
949
}
952
950
953
951
if (rc == SQLITE_DONE && !multiple ) {
952
+ if (self -> statement -> is_dml ) {
953
+ self -> rowcount = (long )sqlite3_changes (self -> connection -> db );
954
+ }
954
955
stmt_reset (self -> statement );
955
956
Py_CLEAR (self -> statement );
956
957
}
@@ -1125,6 +1126,9 @@ pysqlite_cursor_iternext(pysqlite_Cursor *self)
1125
1126
}
1126
1127
int rc = stmt_step (stmt );
1127
1128
if (rc == SQLITE_DONE ) {
1129
+ if (self -> statement -> is_dml ) {
1130
+ self -> rowcount = (long )sqlite3_changes (self -> connection -> db );
1131
+ }
1128
1132
(void )stmt_reset (self -> statement );
1129
1133
}
1130
1134
else if (rc != SQLITE_ROW ) {
0 commit comments