A transaction is commit or rollback. An uncommitted file DB can look empty in a second connection.
Goal
Rollback an insert and print the leftover rows.
import sqlite3
con = sqlite3.connect(":memory:")
con.execute("CREATE TABLE t (n INTEGER)")
con.execute("BEGIN")
con.execute("INSERT INTO t VALUES (1)")
con.execute("ROLLBACK")
print(con.execute("SELECT * FROM t").fetchall())
con.close()import sqlite3
con = sqlite3.connect(":memory:")
con.execute("CREATE TABLE t (n INTEGER)")
con.execute("BEGIN")
con.execute("INSERT INTO t VALUES (1)")
con.execute("COMMIT")
print(con.execute("SELECT * FROM t").fetchall())
con.close()import sqlite3
con = sqlite3.connect("kiosk.db")
con.execute("CREATE TABLE IF NOT EXISTS t (n INTEGER)")
con.execute("DELETE FROM t")
con.execute("INSERT INTO t VALUES (7)")
con.commit()
con2 = sqlite3.connect("kiosk.db")
print(con2.execute("SELECT * FROM t").fetchall())
con.close(); con2.close()import sqlite3
con = sqlite3.connect(":memory:")
con.execute("CREATE TABLE t (n INTEGER)")
try:
con.execute("BEGIN")
con.execute("INSERT INTO t VALUES (1)")
raise RuntimeError("boom")
except RuntimeError:
con.rollback()
print(con.execute("SELECT * FROM t").fetchall())
con.close()