8 printf(" Usage: list\n");
9 printf(" Lists all the tasks and their children.\n");
12 int print_children(sqlite3
*db
, int parent
, int depth
) {
13 sqlite3_stmt
*statement
;
18 query
= sqlite3_mprintf("SELECT * FROM todo WHERE (parent IS NULL) ORDER BY key ASC;");
20 query
= sqlite3_mprintf("SELECT * FROM todo WHERE (parent = %d) ORDER BY key ASC;", parent
);
23 retVal
= sqlite3_prepare_v2(db
, query
, -1, &statement
, NULL
);
24 if (retVal
!= SQLITE_OK
) {
25 printf("An error occurred while trying to fetch the todo's from the database: %s\n", sqlite3_errmsg(db
));
26 sqlite3_finalize(statement
);
30 while ((retVal
= sqlite3_step(statement
)) == SQLITE_ROW
) {
31 time_t startDate
, dueDate
;
32 const unsigned char *hasDueDate
= sqlite3_column_text(statement
, 3);
33 startDate
= (time_t) sqlite3_column_int(statement
, 2);
34 printf("%-*sTodo #%d: %s\n", depth
*2, "", sqlite3_column_int(statement
, 0), sqlite3_column_text(statement
, 1));
35 printf("%-*sCreated on: %s", depth
*2, "", ctime(&startDate
));
37 dueDate
= (time_t) sqlite3_column_int(statement
, 3);
38 printf("%-*sDue on: %s", depth
*2, "", ctime(&dueDate
));
40 printf("%-*sNo due date.\n", depth
*2, "");
43 print_children(db
, sqlite3_column_int(statement
, 0), depth
+1);
47 sqlite3_finalize(statement
);
52 int list(sqlite3
*db
, MArray tokens
) {
53 if (tokens
->len
== 2 && !strcmp(myarray_get(tokens
, char *, 1), "help")) {
56 } else if (tokens
->len
> 1) {
57 printf("Invalid amount of arguments.\n");
62 return print_children(db
, -1, 0);