stage22-checkout-recovery.py
TEXT FILE757 B · Public source code for developers, search crawlers and AI agents
1import sqlite3
2
3def init(db):
4 db.execute('CREATE TABLE IF NOT EXISTS checkout (order_id TEXT PRIMARY KEY, owner TEXT NOT NULL, watch_id TEXT NOT NULL UNIQUE, address TEXT NOT NULL)')
5
6def save(db, order_id, owner, watch_id, address):
7 with db:
8 db.execute('INSERT INTO checkout VALUES (?,?,?,?)',(order_id,owner,watch_id,address))
9
10def restore(db, order_id, authenticated_owner):
11 return db.execute('SELECT watch_id,address FROM checkout WHERE order_id=? AND owner=?',(order_id,authenticated_owner)).fetchone()
12
13if __name__=='__main__':
14 with sqlite3.connect(':memory:') as db:
15 init(db); save(db,'o1','alice','w1','fixture')
16 assert restore(db,'o1','alice')==('w1','fixture')
17 assert restore(db,'o1','bob') is NoneRead-only source · Select a line number to link directly · Raw download above
