@@ -150,13 +150,14 @@ namespace sqlite {
150
150
151
151
void execute () {
152
152
int hresult;
153
+ used (true ); /* prevent from executing again when goes out of scope */
153
154
154
155
while ((hresult = sqlite3_step (_stmt.get ())) == SQLITE_ROW) {}
155
156
156
157
if (hresult != SQLITE_DONE) {
157
158
exceptions::throw_sqlite_error (hresult, sql ());
158
159
}
159
- used ( true ); /* prevent from executing again when goes out of scope */
160
+
160
161
}
161
162
162
163
std::string sql () {
@@ -173,7 +174,12 @@ namespace sqlite {
173
174
return sqlite3_sql (_stmt.get ());
174
175
}
175
176
176
- void used (bool state) { execution_started = state; }
177
+ void used (bool state) {
178
+ if (execution_started == true && state == true ) {
179
+ throw sqlite_exception (" Already used statement executed again! Please reset() first!" ,sql ());
180
+ }
181
+ execution_started = state;
182
+ }
177
183
bool used () const { return execution_started; }
178
184
179
185
private:
@@ -186,8 +192,8 @@ namespace sqlite {
186
192
bool execution_started = false ;
187
193
188
194
void _extract (std::function<void (void )> call_back) {
189
- execution_started = true ;
190
195
int hresult;
196
+ used (true );
191
197
192
198
while ((hresult = sqlite3_step (_stmt.get ())) == SQLITE_ROW) {
193
199
call_back ();
@@ -196,12 +202,11 @@ namespace sqlite {
196
202
if (hresult != SQLITE_DONE) {
197
203
exceptions::throw_sqlite_error (hresult, sql ());
198
204
}
199
- reset ();
200
205
}
201
206
202
207
void _extract_single_value (std::function<void (void )> call_back) {
203
- execution_started = true ;
204
208
int hresult;
209
+ used (true );
205
210
206
211
if ((hresult = sqlite3_step (_stmt.get ())) == SQLITE_ROW) {
207
212
call_back ();
@@ -216,7 +221,6 @@ namespace sqlite {
216
221
if (hresult != SQLITE_DONE) {
217
222
exceptions::throw_sqlite_error (hresult, sql ());
218
223
}
219
- reset ();
220
224
}
221
225
222
226
#ifdef _MSC_VER
@@ -307,7 +311,7 @@ namespace sqlite {
307
311
~database_binder () noexcept (false ) {
308
312
/* Will be executed if no >>op is found, but not if an exception
309
313
is in mid flight */
310
- if (!execution_started && !_has_uncaught_exception && _stmt) {
314
+ if (!used () && !_has_uncaught_exception && _stmt) {
311
315
execute ();
312
316
}
313
317
}
0 commit comments