summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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);