@@ -830,16 +830,12 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
830
830
}
831
831
}
832
832
833
- if (self -> statement != NULL ) {
834
- /* There is an active statement */
835
- stmt_reset (self -> statement );
836
- }
837
-
838
833
/* reset description */
839
834
Py_INCREF (Py_None );
840
835
Py_SETREF (self -> description , Py_None );
841
836
842
837
if (self -> statement ) {
838
+ // Reset pending statements on this cursor.
843
839
(void )stmt_reset (self -> statement );
844
840
}
845
841
@@ -879,6 +875,7 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
879
875
}
880
876
}
881
877
878
+ assert (!sqlite3_stmt_busy (self -> statement -> st ));
882
879
while (1 ) {
883
880
parameters = PyIter_Next (parameters_iter );
884
881
if (!parameters ) {
@@ -902,7 +899,6 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
902
899
PyErr_Clear ();
903
900
}
904
901
}
905
- (void )stmt_reset (self -> statement );
906
902
_pysqlite_seterror (state , self -> connection -> db );
907
903
goto error ;
908
904
}
@@ -944,16 +940,8 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
944
940
}
945
941
}
946
942
947
- if (rc == SQLITE_DONE && ! multiple ) {
943
+ if (rc == SQLITE_DONE ) {
948
944
if (self -> statement -> is_dml ) {
949
- self -> rowcount = (long )sqlite3_changes (self -> connection -> db );
950
- }
951
- stmt_reset (self -> statement );
952
- Py_CLEAR (self -> statement );
953
- }
954
-
955
- if (multiple ) {
956
- if (self -> statement -> is_dml && rc == SQLITE_DONE ) {
957
945
self -> rowcount += (long )sqlite3_changes (self -> connection -> db );
958
946
}
959
947
stmt_reset (self -> statement );
@@ -980,11 +968,17 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
980
968
self -> locked = 0 ;
981
969
982
970
if (PyErr_Occurred ()) {
971
+ if (self -> statement ) {
972
+ (void )stmt_reset (self -> statement );
973
+ Py_CLEAR (self -> statement );
974
+ }
983
975
self -> rowcount = -1L ;
984
976
return NULL ;
985
- } else {
986
- return Py_NewRef ((PyObject * )self );
987
977
}
978
+ if (self -> statement && !sqlite3_stmt_busy (self -> statement -> st )) {
979
+ Py_CLEAR (self -> statement );
980
+ }
981
+ return Py_NewRef ((PyObject * )self );
988
982
}
989
983
990
984
/*[clinic input]
@@ -1111,11 +1105,7 @@ pysqlite_cursor_iternext(pysqlite_Cursor *self)
1111
1105
1112
1106
sqlite3_stmt * stmt = self -> statement -> st ;
1113
1107
assert (stmt != NULL );
1114
- if (sqlite3_data_count (stmt ) == 0 ) {
1115
- (void )stmt_reset (self -> statement );
1116
- Py_CLEAR (self -> statement );
1117
- return NULL ;
1118
- }
1108
+ assert (sqlite3_data_count (stmt ) != 0 );
1119
1109
1120
1110
self -> locked = 1 ; // GH-80254: Prevent recursive use of cursors.
1121
1111
PyObject * row = _pysqlite_fetch_one_row (self );
0 commit comments