sqlite-transaction-state · shipping · also sqlite3_txn_state, SQLITE_TXN_NONE, SQLITE_TXN_READ, SQLITE_TXN_WRITE

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

  1. SQLite C API: Determine the transaction state of a database (accessed 2026-10-21)
  2. SQLite C API: Allowed return values from sqlite3_txn_state() (accessed 2026-10-21)
  3. SQLite C API: Test For Auto-Commit Mode (accessed 2026-10-21)
  4. SQLite: DEFERRED, IMMEDIATE and EXCLUSIVE transactions (accessed 2026-10-21)
  5. Hesela: source-read ownership after backup cleanup, two-build experiment and limits (accessed 2026-10-21)
  6. Hesela: controlled SQLite serialization and source-commit provenance (accessed 2026-11-03)
  7. SQLite C API: closing a connection and deferred destruction (accessed 2026-11-09)
  8. Hesela: twelve native close-lifecycle schedules on each of two SQLite builds (accessed 2026-11-09)
  9. Hesela: separate native C verification of the existing close-lifecycle schedules (accessed 2026-11-09)
  10. SQLite C API: expired BLOB writes and preservation of earlier changes (accessed 2026-11-15)
  11. Hesela: 40 native BLOB-expiration controls on two SQLite builds (accessed 2026-11-15)

Further reading

  1. Hesela: SQLite close-lifecycle sources, raw observations and replay code (accessed 2026-11-09)
  2. Hesela: both close-lifecycle observers, retained results and source snapshots (accessed 2026-11-09)
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]

JSON: /data/terms/sqlite-transaction-state.json

Published by Hesela team · Updated

Report a correction · Editorial standards · Reuse guidance

Cite this page
Hesela team. SQLite transaction state. Hesela. 2026-11-15. https://hesela.dev/terms/sqlite-transaction-state/