Before you tell me to read the docs, yes I have read them. But my own tests tell me I can sometimes call repeatedly sqlite3_step() on some prepared statements without resetting them first. Examples are: BEGIN and COMMIT. Can you shed some light on when I need to reset a prepared statement, as I would like to avoid making the call whenever possible?
EDIT: The docs say (my bold):
The life-cycle of a prepared statement object usually goes like this:
From the sqlite sources:
/* We used to require that sqlite3_reset() be called before retrying
** sqlite3_step() after any error or after SQLITE_DONE. But beginning
** with version 3.7.0, we changed this so that sqlite3_reset() would
** be called automatically instead of throwing the SQLITE_MISUSE error.
** This "automatic-reset" change is not technically an incompatibility,
** since any application that receives an SQLITE_MISUSE is broken by
** definition.
**
** Nevertheless, some published applications that were originally written
** for version 3.6.23 or earlier do in fact depend on SQLITE_MISUSE
** returns, and those were broken by the automatic-reset change. As a
** a work-around, the SQLITE_OMIT_AUTORESET compile-time restores the
** legacy behavior of returning SQLITE_MISUSE for cases where the
** previous sqlite3_step() returned something other than a SQLITE_LOCKED
** or SQLITE_BUSY error.
*/
So with version 3.7.0 sqlite_reset is not needed if you reach SQLITE_DONE and want to step through again.
You need to call sqlite3_finalize to free the statement when you are done with it.see https://www.sqlite.org/c3ref/finalize.html
One more issue with not resetting statement, that I stumbled upon, is that DB may remain locked until the prepared statement is reset. E.g. sqlite3_wal_checkpoint() would return SQL_LOCKED.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With