SQLite transaction state
SQLite transaction state reports whether a named database on a connection currently has no transaction, a read transaction or a write transaction.
sqlite3_txn_state(D, S) reports schema S. A NULL schema returns the highest state across schemas: NONE (0), READ (1) or WRITE (2). An unknown schema name returns -1. The aggregate is not an inventory of individual databases. [1] [2]
BEGIN DEFERRED disables autocommit before a database access establishes a transaction. Disabled autocommit alone does not prove a read snapshot exists. [3] [4]
Hesela's 84-run backup study on two builds found BEGIN alone left main at NONE between steps; BEGIN plus SELECT retained READ after backup completion or cancellation. It did not test attached-schema aggregation. [5]
Track the source schema, ownership and lifetime separately. State is not a snapshot identifier, age, checkpoint backlog or permission to roll back unrelated pooled work.
Serialization preserved uncommitted rows on two builds even after source rollback; the writer remained WRITE during export. An image carries no commit receipt. [6]
Do not query sqlite3_txn_state after successful close_v2. The handle is unusable before deferred destruction. Finalizing pending RETURNING completed an implicit write on two builds; with explicit BEGIN, finalizing the last statement allowed deferred destruction to roll back. [7] [8]
An expired BLOB handle does not undo earlier chunks. In 40 native controls, the implicit path reached NONE with partial BCAA visible before blob_close; explicit BEGIN retained WRITE until commit or rollback. A state sample cannot certify the intended BCDE payload. [12] [13]
Relations
- related
- SQLite Online Backup API, SQLite WAL end mark, Checkpoint starvation, Storage snapshot, SQLite serialization, SQLite savepoint
Limitations
- A per-connection state sample does not identify which other connection is retaining WAL history.
Citations
- SQLite C API: Determine the transaction state of a database
- SQLite C API: Allowed return values from sqlite3_txn_state()
- SQLite C API: Test For Auto-Commit Mode
- SQLite: DEFERRED, IMMEDIATE and EXCLUSIVE transactions
- Hesela: source-read ownership after backup cleanup, two-build experiment and limits
- Hesela: controlled SQLite serialization and source-commit provenance
- SQLite C API: closing a connection and deferred destruction
- Hesela: twelve native close-lifecycle schedules on each of two SQLite builds
- Hesela: separate native C verification of the existing close-lifecycle schedules
- SQLite C API: expired BLOB writes and preservation of earlier changes
- Hesela: 40 native BLOB-expiration controls on two SQLite builds
Further reading
- Hesela: SQLite close-lifecycle sources, raw observations and replay code
- Hesela: both close-lifecycle observers, retained results and source snapshots
Sources & caveats
- The close-lifecycle experiment used twelve ordered native C-API schedules per build, not wrapper-language behavior, crash tests or field-rate samples. [8]
- A separate C observer matched all 48 executions (12 schedules, two recorded engine binaries, two harness compiler modes). Same host and binaries, with the earlier packet visible; not external peer review, field samples or power-loss evidence. [10]
- BLOB controls used ten schedules, two journal modes and SQLite 3.45.1/3.54.1 on one host. No concurrent writer, power-loss test, new-defect claim or population estimate. [13]