Test a transaction rolls back on error
Medium70 pts~25 min
- Rollback
- Error handling
- Transactions
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.
Your starter code already declares TEST_URL — never hardcode a host.
Objective
Start a stock reservation, hit a constraint error midway and roll back, then verify no partial change survived.
Your task
- 1BEGIN; decrement product 11's stock by 5.
- 2Insert an order_items row for order 1, product 11, quantity 0, unit_price 34.99; the CHECK fails.
- 3ROLLBACK the transaction (SQLite keeps it open after a failed statement, so this is your job).
- 4Verify: SELECT (SELECT stock FROM products WHERE id = 11) AS stock, (SELECT COUNT(*) FROM order_items WHERE order_id = 1) AS order_1_lines.
Acceptance criteria
- A statement fails with CHECK constraint failed
- The last result set shows the original stock and line count
- The script uses ROLLBACK
Constraints
- Every run starts from a freshly seeded database, so your script must include its own setup statements.
- A failing statement is recorded and the script keeps running, so you can trigger an error and verify afterwards.
- Only the last result set of your script is compared, so finish with the verification query.
SQL (SQLite engine) · Database Testing · Transactions & concurrency