def insert(card_info): query_one( ''' INSERT INTO cards (code, card_type, item_id, title) VALUES (?, ?, ?, ?) ''', [ card_info.code, card_info.card_type, card_info.item_id, card_info.title ])
def update(card_info): query_one( ''' UPDATE cards SET card_type = ?, item_id = ?, title = ? WHERE code = ? ''', [ card_info.card_type, card_info.item_id, card_info.title, card_info.code ])
def pop(): current_pos = get_queue_pos() row = query_one('SELECT thing FROM queue WHERE oid = ?', [current_pos]) if not row or not row[0]: return None else: info.set_info(QUEUE_POS, str(current_pos + 1)) return row[0]
def get_card_info(code): row = query_one( 'SELECT code, card_type, item_id, title FROM cards WHERE code = ?', [code]) if row: return CardInfo(row[0], row[1], row[2], row[3]) else: return None
def enqueue(thing): query_one('INSERT INTO queue(thing) VALUES (?)', [thing])
def item_has_card(item_id): return query_one('SELECT 1 FROM cards WHERE item_id = ?', [item_id]) is not None
def get_largest_code(): row = query_one('SELECT code FROM cards ORDER BY code DESC LIMIT 1') if row: return int(row[0]) else: return 0
def get_info(key): row = query_one('SELECT value FROM info WHERE key = ?', [key]) if row: return row[0] else: return None
def set_info(key, value): if (get_info(key)): query_one('UPDATE info SET value = ? WHERE key = ?', [str(value), key]) else: query_one('INSERT INTO info (key, value) VALUES (?, ?)', [key, str(value)])