Sqlite3 Tutorial Query Python Fixed Fix <Safe>

def list_tasks(): with sqlite3.connect(DB_NAME) as conn: conn.row_factory = sqlite3.Row cursor = conn.cursor() cursor.execute("SELECT * FROM tasks") for row in cursor.fetchall(): status = "✓" if row["completed"] else "✗" print(f"row['id']. row['title'] [status]")

or use a with block to prevent locking.

To retrieve data, we use SELECT . We can configure the connection to return user-friendly Row objects (dictionary-like) instead of standard tuples, which makes code more readable. sqlite3 tutorial query python fixed