SQLite Forum

Cancelling the query
> And at some point of time I will run the SELECT statement with _prepare/_step/_finalize again in a thread. Now when I call sqlite3_interrupt - which operation will be cancelled?

sqlite3_interrupt(sqlite3*) sends an interrupt to all statements currently executing on the connection and continues to do so until all statements executing on the connection have been interrupted, at which point the interrupt flag on the connection is reset.  See the documentation <https://sqlite.org/c3ref/interrupt.html>, particularly the last paragraph.

 > What will happen with the statement handle after this call? Should there be a _finalize call?

Which statement handle?  Do you mean the handle of the statement which was interrupted and returned an SQLITE_INTERRUPT from sqlite3_step?  There is no effect on the statement other than stopping its execution.  If you are done with the statement you should finalize it to prevent memory leaks.  See also the documentation referenced above.

 > Is there another SQLite API that will allow to cancel the running statement (see question 1)?

That would depend on what you mean.  You can stop executing a statement at any time and reset/finalize it.

In other words, you run a statement like this:

statement = sqlite3_prepare(...)
while (rc = sqlite3_step(statement)
  if ((...I feel like stopping ...) || (rc != SQLITE_ROW))
  ... process the row ...