@@ -244,87 +244,65 @@ void Statement::bind(const char* apName)
244
244
// Execute a step of the query to fetch one row of results
245
245
bool Statement::executeStep ()
246
246
{
247
- if (false == mbDone)
247
+ const int ret = tryExecuteStep ();
248
+ if ((SQLITE_ROW != ret) && (SQLITE_DONE != ret)) // on row or no (more) row ready, else it's a problem
248
249
{
249
- const int ret = sqlite3_step (mStmtPtr );
250
- if (SQLITE_ROW == ret) // one row is ready : call getColumn(N) to access it
251
- {
252
- mbOk = true ;
253
- }
254
- else if (SQLITE_DONE == ret) // no (more) row ready : the query has finished executing
255
- {
256
- mbOk = false ;
257
- mbDone = true ;
258
- }
259
- else
260
- {
261
- mbOk = false ;
262
- mbDone = false ;
263
- throw SQLite::Exception (mStmtPtr , ret);
264
- }
265
- }
266
- else
267
- {
268
- throw SQLite::Exception (" Statement needs to be reseted." );
250
+ throw SQLite::Exception (mStmtPtr , ret);
269
251
}
270
252
271
253
return mbOk; // true only if one row is accessible by getColumn(N)
272
254
}
273
255
274
- int Statement::tryExecuteStep () noexcept
256
+ // Execute a one-step query with no expected result
257
+ int Statement::exec ()
275
258
{
276
- const int ret = sqlite3_step (mStmtPtr );
277
- if (SQLITE_ROW == ret) // one row is ready : call getColumn(N) to access it
278
- {
279
- mbOk = true ;
280
- }
281
- else if (SQLITE_DONE == ret) // no (more) row ready : the query has finished executing
282
- {
283
- mbOk = false ;
284
- mbDone = true ;
285
- }
286
- else
259
+ const int ret = tryExecuteStep ();
260
+ if (SQLITE_DONE != ret) // the statement has finished executing successfully
287
261
{
288
- mbOk = false ;
289
- mbDone = false ;
262
+ if (SQLITE_ROW == ret)
263
+ {
264
+ throw SQLite::Exception (" exec() does not expect results. Use executeStep." );
265
+ }
266
+ else
267
+ {
268
+ throw SQLite::Exception (mStmtPtr , ret);
269
+ }
290
270
}
291
271
292
- return ret;
272
+ // Return the number of rows modified by those SQL statements (INSERT, UPDATE or DELETE)
273
+ return sqlite3_changes (mStmtPtr );
293
274
}
294
275
295
- // Execute a one-step query with no expected result
296
- int Statement::exec ()
276
+ int Statement::tryExecuteStep () noexcept
297
277
{
298
278
if (false == mbDone)
299
279
{
300
280
const int ret = sqlite3_step (mStmtPtr );
301
- if (SQLITE_DONE == ret) // the statement has finished executing successfully
281
+ if (SQLITE_ROW == ret) // one row is ready : call getColumn(N) to access it
302
282
{
303
- mbOk = false ;
304
- mbDone = true ;
283
+ mbOk = true ;
305
284
}
306
- else if (SQLITE_ROW == ret)
285
+ else if (SQLITE_DONE == ret) // no (more) row ready : the query has finished executing
307
286
{
308
287
mbOk = false ;
309
- mbDone = false ;
310
- throw SQLite::Exception (" exec() does not expect results. Use executeStep." );
288
+ mbDone = true ;
311
289
}
312
290
else
313
291
{
314
292
mbOk = false ;
315
293
mbDone = false ;
316
- throw SQLite::Exception (mStmtPtr , ret);
317
294
}
295
+
296
+ return ret;
318
297
}
319
298
else
320
299
{
321
- throw SQLite::Exception (" Statement need to be reseted." );
300
+ // Statement needs to be reseted !
301
+ return SQLITE_MISUSE;
322
302
}
323
-
324
- // Return the number of rows modified by those SQL statements (INSERT, UPDATE or DELETE)
325
- return sqlite3_changes (mStmtPtr );
326
303
}
327
304
305
+
328
306
// Return a copy of the column data specified by its index starting at 0
329
307
// (use the Column copy-constructor)
330
308
Column Statement::getColumn (const int aIndex)
0 commit comments