@@ -101,6 +101,24 @@ pysqlite_cursor_init_impl(pysqlite_Cursor *self,
101
101
return 0 ;
102
102
}
103
103
104
+ static inline int
105
+ stmt_reset (pysqlite_Statement * self )
106
+ {
107
+ int rc = SQLITE_OK ;
108
+
109
+ if (self -> in_use && self -> st ) {
110
+ Py_BEGIN_ALLOW_THREADS
111
+ rc = sqlite3_reset (self -> st );
112
+ Py_END_ALLOW_THREADS
113
+
114
+ if (rc == SQLITE_OK ) {
115
+ self -> in_use = 0 ;
116
+ }
117
+ }
118
+
119
+ return rc ;
120
+ }
121
+
104
122
static int
105
123
cursor_traverse (pysqlite_Cursor * self , visitproc visit , void * arg )
106
124
{
@@ -124,7 +142,7 @@ cursor_clear(pysqlite_Cursor *self)
124
142
Py_CLEAR (self -> row_factory );
125
143
if (self -> statement ) {
126
144
/* Reset the statement if the user has not closed the cursor */
127
- pysqlite_statement_reset (self -> statement );
145
+ stmt_reset (self -> statement );
128
146
Py_CLEAR (self -> statement );
129
147
}
130
148
@@ -544,7 +562,7 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
544
562
545
563
if (self -> statement != NULL ) {
546
564
/* There is an active statement */
547
- pysqlite_statement_reset (self -> statement );
565
+ stmt_reset (self -> statement );
548
566
}
549
567
550
568
/* reset description and rowcount */
@@ -553,7 +571,7 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
553
571
self -> rowcount = 0L ;
554
572
555
573
if (self -> statement ) {
556
- (void )pysqlite_statement_reset (self -> statement );
574
+ (void )stmt_reset (self -> statement );
557
575
}
558
576
559
577
PyObject * stmt = get_statement_from_cache (self , operation );
@@ -577,7 +595,7 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
577
595
}
578
596
}
579
597
580
- pysqlite_statement_reset (self -> statement );
598
+ stmt_reset (self -> statement );
581
599
pysqlite_statement_mark_dirty (self -> statement );
582
600
583
601
/* We start a transaction implicitly before a DML statement.
@@ -614,7 +632,7 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
614
632
PyErr_Clear ();
615
633
}
616
634
}
617
- (void )pysqlite_statement_reset (self -> statement );
635
+ (void )stmt_reset (self -> statement );
618
636
_pysqlite_seterror (state , self -> connection -> db );
619
637
goto error ;
620
638
}
@@ -663,12 +681,12 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
663
681
}
664
682
665
683
if (rc == SQLITE_DONE && !multiple ) {
666
- pysqlite_statement_reset (self -> statement );
684
+ stmt_reset (self -> statement );
667
685
Py_CLEAR (self -> statement );
668
686
}
669
687
670
688
if (multiple ) {
671
- pysqlite_statement_reset (self -> statement );
689
+ stmt_reset (self -> statement );
672
690
}
673
691
Py_XDECREF (parameters );
674
692
}
@@ -824,7 +842,7 @@ pysqlite_cursor_iternext(pysqlite_Cursor *self)
824
842
sqlite3_stmt * stmt = self -> statement -> st ;
825
843
assert (stmt != NULL );
826
844
if (sqlite3_data_count (stmt ) == 0 ) {
827
- (void )pysqlite_statement_reset (self -> statement );
845
+ (void )stmt_reset (self -> statement );
828
846
Py_CLEAR (self -> statement );
829
847
return NULL ;
830
848
}
@@ -835,7 +853,7 @@ pysqlite_cursor_iternext(pysqlite_Cursor *self)
835
853
}
836
854
int rc = stmt_step (stmt );
837
855
if (rc == SQLITE_DONE ) {
838
- (void )pysqlite_statement_reset (self -> statement );
856
+ (void )stmt_reset (self -> statement );
839
857
}
840
858
else if (rc != SQLITE_ROW ) {
841
859
(void )_pysqlite_seterror (self -> connection -> state ,
@@ -1005,7 +1023,7 @@ pysqlite_cursor_close_impl(pysqlite_Cursor *self)
1005
1023
}
1006
1024
1007
1025
if (self -> statement ) {
1008
- (void )pysqlite_statement_reset (self -> statement );
1026
+ (void )stmt_reset (self -> statement );
1009
1027
Py_CLEAR (self -> statement );
1010
1028
}
1011
1029
0 commit comments