Small. Fast. Reliable.
Choose any three.
int sqlite3_step(sqlite3_stmt*);
After a
has been prepared using any of
,
,
, or
or one of the legacy interfaces
or
, this function must be called one or more times to evaluate the statement.
The details of the behavior of the sqlite3_step() interface depend on whether the statement was prepared using the newer "vX" interfaces
,
,
,
or the older legacy interfaces
and
. The use of the new "vX" interface is recommended for new applications but the legacy interface will continue to be supported.
In the legacy interface, the return value will be either
,
,
,
, or
. With the "v2" interface, any of the other
or
might be returned as well.
means that the database engine was unable to acquire the database locks it needs to do its job. If the statement is a
or occurs outside of an explicit transaction, then you can retry the statement. If the statement is not a
and occurs within an explicit transaction then you should rollback the transaction before continuing.
means that the statement has finished executing successfully. sqlite3_step() should not be called again on this virtual machine without first calling
to reset the virtual machine back to its initial state.
If the SQL statement being executed returns any data, then
is returned each time a new row of data is ready for processing by the caller. The values may be accessed using the
. sqlite3_step() is called again to retrieve the next row of data.
means that a run-time error (such as a constraint violation) has occurred. sqlite3_step() should not be called again on the VM. More information may be found by calling
. With the legacy interface, a more specific error code (for example,
,
,
, and so forth) can be obtained by calling
on the
. In the "v2" interface, the more specific error code is returned directly by sqlite3_step().
means that the this routine was called inappropriately. Perhaps it was called on a
that has already been
or on one that had previously returned
or
. Or it could be the case that the same database connection is being used by two or more threads at the same moment in time.
For all versions of SQLite up to and including 3.6.23.1, a call to
was required after sqlite3_step() returned anything other than
before any subsequent invocation of sqlite3_step(). Failure to reset the prepared statement using
would result in an
return from sqlite3_step(). But after
(2010-03-26), sqlite3_step() began calling
automatically in this circumstance rather than returning
. This is not considered a compatibility break because any application that ever receives an SQLITE_MISUSE error is broken by definition. The
compile-time option can be used to restore the legacy behavior.
Goofy Interface Alert: In the legacy interface, the sqlite3_step() API always returns a generic error code,
, following any error other than
and
. You must call
or
in order to find one of the specific
that better describes the error. We admit that this is a goofy design. The problem has been fixed with the "v2" interface. If you prepare all of your SQL statements using
or
or
or
instead of the legacy
and
interfaces, then the more specific
are returned directly by sqlite3_step(). The use of the "vX" interfaces is recommended.
See also lists of
,
, and
.