Checkpoint

Checkpoint: The Supply Desk

The Guild supply desk keeps every item in one table:

item island qty price
rope Amber Isle 3 4
wick Amber Isle 0 1

qty is how many are in stock. price is in whole coins. Customers ask questions all day. Let's answer them with SQL.

This checkpoint uses the whole chapter: INSERT, SELECT, WHERE, ORDER BY, and ? placeholders. One new trick: LIMIT ? takes a placeholder too.

Assignment

Use ? placeholders for every value that comes from an argument.

  1. restock(conn, item, island, qty, price) inserts one row.
  2. in_stock(conn, island) returns a list of (item, qty) for that island with qty above 0, items A to Z.
  3. bargains(conn, max_price, how_many) returns a list of (item, price) with price at most max_price. Cheapest first, ties A to Z by item, and at most how_many rows.

The program should print:

[('oil', 6), ('rope', 3)]
[('wick', 1), ('map', 2)]