SQL (SQLite engine)

Test a lost update scenario

Hard120 pts~45 min
  • Lost update
  • Concurrency
  • Savepoints
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-lost-update-scenario

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

Objective

Reproduce two clerks overwriting each other's stock change, then fix it with atomic relative updates.

Your task

  1. 1SAVEPOINT lost_update; both clerks read product 12's stock (500), e.g. into a TEMP table.
  2. 2Clerk A writes 500 - 30 and clerk B writes 500 - 20 as absolute values; observe 480 instead of 450.
  3. 3ROLLBACK TO lost_update and RELEASE it to undo the buggy run.
  4. 4Apply both sales safely: UPDATE products SET stock = stock - 30 WHERE id = 12, then stock - 20.
  5. 5Verify: SELECT id, stock FROM products WHERE id = 12 returns 450.

Acceptance criteria

  • Product 12 ends with stock 450
  • The last result set is (12, 450)
  • The fix uses a relative update (stock = stock - n)

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