← Quiz: Distributed Transactions and Sagas: all 10 questions
Quiz: Distributed Transactions and Sagas · Question 9 of 10
What does this print? (code)
What does this print?
import sqlite3
db = sqlite3.connect(":memory:")
db.execute("CREATE TABLE t (x INTEGER)")
try:
with db:
db.execute("INSERT INTO t VALUES (1)")
raise ValueError("crash")
except ValueError:
pass
print(db.execute("SELECT COUNT(*) FROM t").fetchone()[0])
- A.0
- B.1
- C.2
- D.An error
Answer & explanation
Correct answer: 0
The exception inside with db: rolls back the transaction, so the insert is undone.
Can you get the rest right without peeking?
Take the timed Quiz: Distributed Transactions and Sagas quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →