I've been working on this little mobile app that tracks tasks, whatever they may be.
The main view has a grid containing task lists, each of which have a title and a status indicator, for example:
TITLE STATUS
Tasks1 Done
Tasks2
Tasks3 All done
Selecting a task list shows all the tasks on that list one by one. The user can mark each task as Done (1) or Not done (0), or just move to the next one (leave as NULL).
If all tasks have been marked Done, the status on the grid is All done. However, if any task has been marked Not done, the status is (just) Done. If any task has been left unmarked, the status is empty.
I have two tables:
CREATE TABLE tasklists (id_list INTEGER, title TEXT)
CREATE TABLE tasks (id_list INTEGER, id_task INTEGER, description TEXT, status INTEGER)
Currently the grid is populated with "SELECT * FROM tasklists", then for each row I fetch the total number of tasks, number of tasks marked Done and number of tasks marked Not done, and finally update the status accordingly.
Well, it works, but it's not very elegant, especially if I'd want to show only some of the task lists (e.g. ones not marked All done).
So I'm wondering if there is a way to populate the grid with a single SQL statement. I've looked at CASE expressions, but haven't figured out how to handle the three-state status column..
Or maybe I should add a status column to the tasklists table, but then I'd need a neat way to update that..
Any tips? I'm using the SQLite provider, if it matters.
The main view has a grid containing task lists, each of which have a title and a status indicator, for example:
TITLE STATUS
Tasks1 Done
Tasks2
Tasks3 All done
Selecting a task list shows all the tasks on that list one by one. The user can mark each task as Done (1) or Not done (0), or just move to the next one (leave as NULL).
If all tasks have been marked Done, the status on the grid is All done. However, if any task has been marked Not done, the status is (just) Done. If any task has been left unmarked, the status is empty.
I have two tables:
CREATE TABLE tasklists (id_list INTEGER, title TEXT)
CREATE TABLE tasks (id_list INTEGER, id_task INTEGER, description TEXT, status INTEGER)
Currently the grid is populated with "SELECT * FROM tasklists", then for each row I fetch the total number of tasks, number of tasks marked Done and number of tasks marked Not done, and finally update the status accordingly.
Well, it works, but it's not very elegant, especially if I'd want to show only some of the task lists (e.g. ones not marked All done).
So I'm wondering if there is a way to populate the grid with a single SQL statement. I've looked at CASE expressions, but haven't figured out how to handle the three-state status column..
Or maybe I should add a status column to the tasklists table, but then I'd need a neat way to update that..
Any tips? I'm using the SQLite provider, if it matters.
Comment