diff --git a/apps/heimdall/web-app.yaml b/apps/heimdall/web-app.yaml index fc59ff7..ec1a60f 100644 --- a/apps/heimdall/web-app.yaml +++ b/apps/heimdall/web-app.yaml @@ -113,6 +113,9 @@ data: def columns(conn, table): return {row[1] for row in conn.execute(f"pragma table_info({table})")} + def quote_identifier(name): + return '"' + name.replace('"', '""') + '"' + def wait_for_items_table(db_path): while True: try: @@ -130,7 +133,7 @@ data: for order, link in enumerate(links): existing = conn.execute( - "select id from items where title = ?", + 'select "id" from "items" where "title" = ?', (link["title"],), ).fetchone() values = { @@ -155,10 +158,10 @@ data: name for name in values if name in item_columns and name not in ("id", "title", "created_at") ] - assignments = ", ".join(f"{name} = ?" for name in update_columns) + assignments = ", ".join(f"{quote_identifier(name)} = ?" for name in update_columns) params = [values[name] for name in update_columns] params.append(existing[0]) - conn.execute(f"update items set {assignments} where id = ?", params) + conn.execute(f'update "items" set {assignments} where "id" = ?', params) continue insert_columns = [ @@ -166,8 +169,9 @@ data: if name in item_columns and name != "deleted_at" ] placeholders = ", ".join("?" for _ in insert_columns) + quoted_insert_columns = ", ".join(quote_identifier(name) for name in insert_columns) conn.execute( - f"insert into items ({', '.join(insert_columns)}) values ({placeholders})", + f'insert into "items" ({quoted_insert_columns}) values ({placeholders})', [values[name] for name in insert_columns], )