SQLite Forum

Feature request: expose additional state to identify left-open statements
I have an application that keeps a pool of database connections open in multi-thread mode, with routines that need a connection being allocated one from the pool, which they return when finished with it. The exact details of the implementation are such that the routine can accidentally return a connection to the pool while a prepared statement derived from it is still alive, which can cause undefined behavior when the statement is operated on later (including to destroy it).

I have some debug-mode code that, when returning a connection to the pool, first validates that it isn't associated with any stale statements (via `sqlite3_next_stmt`), and fails an assertion it does. The problem I've run into is that several sqlite extensions create persistent prepared statements that aren't finalized until the entire session is closed, so I need to ignore those. Currently I'm doing so by allow-listing their query text, but that's not a very robust solution.

The best way to identify these persistent statements seems to be by the `SQLITE_PREPARE_PERSISTENT` flag set at their creation, but there doesn't seem to be any way for an application to determine if that flag was set on a statement. Could this be exposed?

Additionally, SQLite currently exposes `sqlite3_stmt_busy`, which allows a caller to check if a statement hasn't yet been reset _or run to completion_. It might also be useful to expose whether the statement has been stepped since it was last reset (or created).