{
  "slug": "sqlite-transaction-state",
  "term": "SQLite transaction state",
  "aliases": [
    "sqlite3_txn_state",
    "SQLITE_TXN_NONE",
    "SQLITE_TXN_READ",
    "SQLITE_TXN_WRITE"
  ],
  "definition": "SQLite transaction state reports whether a named database on a connection currently has no transaction, a read transaction or a write transaction.",
  "note": "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. [api] [states]\n\nBEGIN DEFERRED disables autocommit before a database access establishes a transaction. Disabled autocommit alone does not prove a read snapshot exists. [autocommit] [transactions]\n\nHesela'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. [retention]\n\nTrack the source schema, ownership and lifetime separately. State is not a snapshot identifier, age, checkpoint backlog or permission to roll back unrelated pooled work.\n\nSerialization preserved uncommitted rows on two builds even after source rollback; the writer remained WRITE during export. An image carries no commit receipt. [serialization]\n\nDo 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. [close-lifecycle-contract] [close-lifecycle-data]\n\nAn 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. [blob-write] [blob-evidence]",
  "related": [
    "sqlite-online-backup",
    "sqlite-wal-end-mark",
    "checkpoint-starvation",
    "snapshot",
    "sqlite-serialization",
    "sqlite-savepoint"
  ],
  "citations": [
    {
      "id": "api",
      "title": "SQLite C API: Determine the transaction state of a database",
      "url": "https://sqlite.org/c3ref/txn_state.html",
      "accessed": "2026-10-21"
    },
    {
      "id": "states",
      "title": "SQLite C API: Allowed return values from sqlite3_txn_state()",
      "url": "https://sqlite.org/c3ref/c_txn_none.html",
      "accessed": "2026-10-21"
    },
    {
      "id": "autocommit",
      "title": "SQLite C API: Test For Auto-Commit Mode",
      "url": "https://sqlite.org/c3ref/get_autocommit.html",
      "accessed": "2026-10-21"
    },
    {
      "id": "transactions",
      "title": "SQLite: DEFERRED, IMMEDIATE and EXCLUSIVE transactions",
      "url": "https://sqlite.org/lang_transaction.html#deferred_immediate_and_exclusive_transactions",
      "accessed": "2026-10-21"
    },
    {
      "id": "retention",
      "title": "Hesela: source-read ownership after backup cleanup, two-build experiment and limits",
      "url": "https://hesela.com/analyses/backup-verification-is-not-a-restore-test/#sqlite-backup-retention",
      "accessed": "2026-10-21"
    },
    {
      "id": "serialization",
      "title": "Hesela: controlled SQLite serialization and source-commit provenance",
      "url": "https://hesela.com/analyses/backup-verification-is-not-a-restore-test/#sqlite-serialization",
      "accessed": "2026-11-03"
    },
    {
      "id": "close-lifecycle-contract",
      "title": "SQLite C API: closing a connection and deferred destruction",
      "url": "https://sqlite.org/c3ref/close.html",
      "accessed": "2026-11-09"
    },
    {
      "id": "close-lifecycle-data",
      "title": "Hesela: twelve native close-lifecycle schedules on each of two SQLite builds",
      "url": "https://hesela.dev/research/sqlite-close-lifecycle/summary.json",
      "accessed": "2026-11-09"
    },
    {
      "id": "close-lifecycle-package",
      "title": "Hesela: SQLite close-lifecycle sources, raw observations and replay code",
      "url": "https://hesela.dev/research/sqlite-close-lifecycle/package.zip",
      "accessed": "2026-11-09"
    },
    {
      "id": "close-native-data",
      "title": "Hesela: separate native C verification of the existing close-lifecycle schedules",
      "url": "https://hesela.dev/research/sqlite-close-native-verification/summary.json",
      "accessed": "2026-11-09"
    },
    {
      "id": "close-native-package",
      "title": "Hesela: both close-lifecycle observers, retained results and source snapshots",
      "url": "https://hesela.dev/research/sqlite-close-native-verification/package.zip",
      "accessed": "2026-11-09"
    },
    {
      "id": "blob-write",
      "title": "SQLite C API: expired BLOB writes and preservation of earlier changes",
      "url": "https://www.sqlite.org/c3ref/blob_write.html",
      "accessed": "2026-11-15"
    },
    {
      "id": "blob-evidence",
      "title": "Hesela: 40 native BLOB-expiration controls on two SQLite builds",
      "url": "https://hesela.dev/research/sqlite-blob-expiration/summary.json",
      "accessed": "2026-11-15"
    }
  ],
  "status": "shipping",
  "advantages": [],
  "limitations": [
    "A per-connection state sample does not identify which other connection is retaining WAL history."
  ],
  "supersedes": [],
  "supersededBy": [],
  "firstSeen": null,
  "lastSeen": null,
  "updated": "2026-11-15",
  "provenance": [
    "The close-lifecycle experiment used twelve ordered native C-API schedules per build, not wrapper-language behavior, crash tests or field-rate samples. [close-lifecycle-data]",
    "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. [close-native-data]",
    "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. [blob-evidence]"
  ]
}
