@@ -492,10 +492,9 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
492
492
pysqlite_statement_reset (self -> statement );
493
493
}
494
494
495
- /* reset description and rowcount */
495
+ /* reset description */
496
496
Py_INCREF (Py_None );
497
497
Py_SETREF (self -> description , Py_None );
498
- self -> rowcount = 0L ;
499
498
500
499
func_args = PyTuple_New (1 );
501
500
if (!func_args ) {
@@ -527,6 +526,7 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
527
526
528
527
pysqlite_statement_reset (self -> statement );
529
528
pysqlite_statement_mark_dirty (self -> statement );
529
+ self -> rowcount = self -> statement -> is_dml ? 0L : -1L ;
530
530
531
531
/* We start a transaction implicitly before a DML statement.
532
532
SELECT is the only exception. See #9924. */
@@ -604,12 +604,6 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
604
604
}
605
605
}
606
606
607
- if (self -> statement -> is_dml ) {
608
- self -> rowcount += (long )sqlite3_changes (self -> connection -> db );
609
- } else {
610
- self -> rowcount = -1L ;
611
- }
612
-
613
607
if (!multiple ) {
614
608
Py_BEGIN_ALLOW_THREADS
615
609
lastrowid = sqlite3_last_insert_rowid (self -> connection -> db );
@@ -630,11 +624,17 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
630
624
if (self -> next_row == NULL )
631
625
goto error ;
632
626
} else if (rc == SQLITE_DONE && !multiple ) {
627
+ if (self -> statement -> is_dml ) {
628
+ self -> rowcount = (long )sqlite3_changes (self -> connection -> db );
629
+ }
633
630
pysqlite_statement_reset (self -> statement );
634
631
Py_CLEAR (self -> statement );
635
632
}
636
633
637
634
if (multiple ) {
635
+ if (self -> statement -> is_dml && rc == SQLITE_DONE ) {
636
+ self -> rowcount += (long )sqlite3_changes (self -> connection -> db );
637
+ }
638
638
pysqlite_statement_reset (self -> statement );
639
639
}
640
640
Py_XDECREF (parameters );
@@ -824,7 +824,12 @@ pysqlite_cursor_iternext(pysqlite_Cursor *self)
824
824
if (PyErr_Occurred ()) {
825
825
goto error ;
826
826
}
827
- if (rc != SQLITE_DONE && rc != SQLITE_ROW ) {
827
+ if (rc == SQLITE_DONE ) {
828
+ if (self -> statement -> is_dml ) {
829
+ self -> rowcount = (long )sqlite3_changes (self -> connection -> db );
830
+ }
831
+ }
832
+ else if (rc != SQLITE_ROW ) {
828
833
_pysqlite_seterror (self -> connection -> db , NULL );
829
834
goto error ;
830
835
}
0 commit comments