From 179923499913993e93a6fcf7a9f6e9c62e49cab0 Mon Sep 17 00:00:00 2001 From: Codeball Date: Wed, 24 Aug 2022 10:09:43 +0200 Subject: [PATCH] prompt: before_first_request: After creating the table, if the table is empty, add three rows --- app.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app.py b/app.py index 49953f7..467a90c 100644 --- a/app.py +++ b/app.py @@ -15,6 +15,15 @@ def create_tables(): id INTEGER PRIMARY KEY AUTOINCREMENT, description text, done bool + c.execute("SELECT * FROM tasks") + tasks = c.fetchall() + if len(tasks) == 0: + c.execute("INSERT INTO tasks (description, done) VALUES (:description, :done)", + {"description": "Task 1", "done": 0}) + c.execute("INSERT INTO tasks (description, done) VALUES (:description, :done)", + {"description": "Task 2", "done": 0}) + c.execute("INSERT INTO tasks (description, done) VALUES (:description, :done)", + {"description": "Task 3", "done": 0}) )""") conn.commit() conn.close()