"""Deterministic SQLite SQL schedules; no crash or physical-durability test.""" import argparse import json from pathlib import Path import platform import sqlite3 import tempfile CASES = { "nested-release-rollback": [ "BEGIN", "SAVEPOINT unit", "INSERT INTO t VALUES (1)", "RELEASE unit", "ROLLBACK", ], "outermost-release": [ "SAVEPOINT unit", "INSERT INTO t VALUES (1)", "RELEASE unit", ], "rollback-to-retains-target": [ "BEGIN", "SAVEPOINT unit", "INSERT INTO t VALUES (1)", "ROLLBACK TO unit", "INSERT INTO t VALUES (2)", "ROLLBACK TO unit", "RELEASE unit", "COMMIT", ], "reused-name": [ "BEGIN", "SAVEPOINT unit", "INSERT INTO t VALUES (1)", "SAVEPOINT unit", "INSERT INTO t VALUES (2)", "RELEASE unit", "ROLLBACK TO unit", "RELEASE unit", "COMMIT", ], } def observe(): results = [] with tempfile.TemporaryDirectory(prefix="hesela-savepoint-") as temp: for mode in ("DELETE", "WAL"): for name, statements in CASES.items(): path = Path(temp) / (mode + "-" + name + ".sqlite") writer = sqlite3.connect(path, isolation_level=None) reader = sqlite3.connect(path, isolation_level=None) try: effective = writer.execute("PRAGMA journal_mode=" + mode).fetchone()[0] if effective.upper() != mode: raise RuntimeError("Requested journal mode was not enabled") writer.execute("PRAGMA synchronous=FULL") writer.execute("CREATE TABLE t (value INTEGER PRIMARY KEY)") steps = [] for sql in statements: writer.execute(sql) # Each SELECT is drained; the observer retains no read transaction. steps.append({ "sql": sql, "writer_rows": [r[0] for r in writer.execute("SELECT value FROM t ORDER BY value")], "observer_rows": [r[0] for r in reader.execute("SELECT value FROM t ORDER BY value")], "transaction_open": writer.in_transaction, }) source_id = writer.execute("SELECT sqlite_source_id()").fetchone()[0] options = [r[0] for r in writer.execute("PRAGMA compile_options")] synchronous = writer.execute("PRAGMA synchronous").fetchone()[0] finally: reader.close() writer.close() with sqlite3.connect(path, isolation_level=None) as reopened: rows = [r[0] for r in reopened.execute("SELECT value FROM t ORDER BY value")] results.append({"case": name, "journal_mode": mode, "synchronous": synchronous, "steps": steps, "reopened_rows": rows}) return { "schema_version": 1, "environment": {"python": platform.python_version(), "sqlite": sqlite3.sqlite_version, "sqlite_source_id": source_id, "compile_options": options}, "method": "Eight fresh databases: four ordered SQL schedules in DELETE and WAL mode. Explicit SQL transaction control with Python sqlite3 isolation_level=None. After every statement, complete ordered rows are read by the writer and by a drained, autocommit observer SELECT. transaction_open is the wrapper's low-level autocommit indicator, not sqlite3_txn_state. Normal close and reopen only.", "limits": "Synthetic fixtures, not field data or a performance sample. One recorded runtime per capture. No power loss, process crash, I/O fault, deferred-constraint experiment or physical persistence measurement.", "cases": results, } if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("output", type=Path) args = parser.parse_args() data = observe() with args.output.open("x", encoding="utf-8") as stream: json.dump(data, stream, indent=2) stream.write("\n")