From 22cd6a69daea825a7ff2791feb7fd2dec9594d40 Mon Sep 17 00:00:00 2001 From: augustin64 Date: Wed, 12 Jul 2023 21:32:44 +0200 Subject: [PATCH] Implement done command --- src/db.c | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/src/db.c b/src/db.c index 479e967..dd9a8d0 100644 --- a/src/db.c +++ b/src/db.c @@ -95,9 +95,41 @@ int add_task(task_t t) { return 0; } -int update_task(task_t t) { //TODO - (void)t; - return 1; +int update_task(task_t t) { + sqlite3* db = get_db(); + sqlite3_stmt* stmt; + + int ret = sqlite3_prepare_v2(db, "UPDATE tasks SET text=?2, done=?3, due_to=?4 WHERE id=?1;", -1, &stmt, 0); + + if (ret != SQLITE_OK) { + printf("(get_task) failure fetching data\n"); + return 1; + } + + char str_id[10]; + sprintf(str_id, "%d", (int)t.id); + sqlite3_bind_text(stmt, 1, str_id, -1, SQLITE_STATIC); + sqlite3_bind_text(stmt, 2, t.text, -1, SQLITE_STATIC); + + char str_done[2]; // Just a boolean + sprintf(str_done, "%d", t.done); + sqlite3_bind_text(stmt, 3, str_done, -1, SQLITE_STATIC); + + char str_due_to[15]; + sprintf(str_due_to, "%ld", t.due_to); + sqlite3_bind_text(stmt, 4, str_due_to, -1, SQLITE_STATIC); + + + ret = sqlite3_step(stmt); + + sqlite3_finalize(stmt); + sqlite3_close(db); + + if (ret != SQLITE_DONE) { + printf("Return value: %d\n", ret); + return 1; + } + return 0; }