🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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])
  1. A.0
  2. B.1
  3. C.2
  4. 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 →