summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorFreeArtMan <dos21h@gmail.com>2017-11-22 22:01:20 +0000
committerFreeArtMan <dos21h@gmail.com>2017-11-22 22:01:20 +0000
commitaee6daa406af77c16e209927f51e56034be6d773 (patch)
tree110db8822bbcf47854787317c2fcf084e2f3c99e /cmd
parentafb3657fa2cbc6bd9e5901d6c5590b09d15c2d89 (diff)
downloadagni-aee6daa406af77c16e209927f51e56034be6d773.tar.gz
agni-aee6daa406af77c16e209927f51e56034be6d773.zip
Added TODO/total command, that shows total todo tasks
Diffstat (limited to 'cmd')
-rw-r--r--cmd/cmd_todo.c37
1 files changed, 35 insertions, 2 deletions
diff --git a/cmd/cmd_todo.c b/cmd/cmd_todo.c
index 8cd712d..78dc8b5 100644
--- a/cmd/cmd_todo.c
+++ b/cmd/cmd_todo.c
@@ -108,6 +108,34 @@ static int list_todo(sqlite3 *db, char *user, sds *out)
return 0;
}
+static int list_total(sqlite3 *db, sds *out)
+{
+ int rc;
+ char *err_msg = NULL;
+ sqlite3_stmt *res=NULL;
+
+ char sql_list_total[1024];
+
+ snprintf(sql_list_total, 1024, "SELECT COUNT(*) FROM todo;");
+ printf("%s\n",sql_list_total);
+
+ if ((rc = sqlite3_prepare_v2(db, sql_list_total, -1, &res, 0)) != SQLITE_OK)
+ {
+ printf("Cannot prepare statment: %s\n", sqlite3_errmsg(db));
+ return -1;
+ }
+
+ rc = sqlite3_step(res);
+ if (rc == SQLITE_ROW)
+ {
+ const char *cret = sqlite3_column_text(res, 0);
+ *out = sdscat(*out, cret);
+ }
+ sqlite3_finalize(res);
+
+ return 0;
+}
+
static int del_todo(sqlite3 *db, char *user, int id)
{
int rc;
@@ -267,9 +295,14 @@ void *cmd_todo(void *data)
out_result = sdscatsds(out_result, out_todo);
out_result[sdslen(out_result)-1] = 0; //dirty hack mate
sdsfree(out_todo);
- } else
+ } else if (strncmp(tokens[1],"total",5) == 0)
{
-
+ PRINT("LIST\n");
+ list_total(db, &out_todo);
+ PRINT("%s\n",out_todo);
+ out_result = sdscatsds(out_result, out_todo);
+ //out_result[sdslen(out_result)-1] = 0; //dirty hack mate
+ sdsfree(out_todo);
}
sqlite3_finalize(res);