SQL (SQLite engine)

Test a dirty read is prevented

Hard120 pts~45 min
  • Dirty reads
  • Isolation
  • Rollback
Practice app · Acme Commerce DB

A real SQL database (SQLite engine) seeded with an e-commerce and HR dataset, with schema browser and query runner.

Test URL
/lab/database-testing-test-a-dirty-read-is-prevented

Your starter code already declares TEST_URL — never hardcode a host.

Objective

Simulate a reader and an uncommitted writer and prove the reader's view never contains the writer's rolled-back prices.

Your task

  1. 1Reader: capture committed camera prices with CREATE TEMP TABLE reader_snapshot AS SELECT id, price FROM products WHERE category = 'cameras'.
  2. 2Writer: BEGIN; halve every camera price (price = price * 0.5).
  3. 3Writer aborts: ROLLBACK.
  4. 4Verify: SELECT COUNT(*) AS dirty_rows FROM products p JOIN reader_snapshot s ON s.id = p.id WHERE p.price <> s.price returns 0.

Acceptance criteria

  • temp.reader_snapshot holds the committed camera prices
  • The last result set shows 0 dirty rows
  • The script uses ROLLBACK

Constraints

  • Every run starts from a freshly seeded database, so your script must include its own setup statements.
  • The workbench has a single connection, so concurrent sessions are simulated step by step inside one session (snapshots in TEMP tables, SAVEPOINTs as the other transaction).
  • Only the last result set of your script is compared, so finish with the verification query.

SQL (SQLite engine) · Database Testing · Transactions & concurrency