From 5b5b36c041e8b35c0e6be3008cf7f483be99a515 Mon Sep 17 00:00:00 2001 From: xavi Date: Fri, 20 Sep 2024 12:41:21 -0700 Subject: [PATCH] Modified delete to only delete active tasks TODO: have way to delete completed tasks --- src/dodo.c | 6 +++--- src/dodo.schema | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/dodo.c b/src/dodo.c index db29851..b7c48a1 100644 --- a/src/dodo.c +++ b/src/dodo.c @@ -5,6 +5,7 @@ #include "x_curses.h" #include "dodo.h" +//TODO: check that only one row is modified with sqlite3_change() // FOR DEBUG int callback(void *NotUsed, int argc, char **argv, char **azColName){ @@ -83,8 +84,7 @@ int gen_sql_delete_stmt(sqlite3 *db, sqlite3_stmt** out_stmt, filtered_tasks* ta char sql_query[SQLQUERY_MAX]; int rc = 0; - snprintf(sql_query, SQLQUERY_MAX, "DELETE FROM %s WHERE title='%s' OR active_id='%d'", - task->table, task->title, task->active_id); + snprintf(sql_query, SQLQUERY_MAX, "DELETE FROM %s WHERE (title='%s' OR active_id='%d') AND active_id IS NOT NULL", task->table, task->title, task->active_id); rc = sqlite3_prepare_v2(db, sql_query, -1, out_stmt, NULL); if (checksqlerr(rc, "prepare broken in gen_sql_insert_stmt")){ @@ -484,7 +484,7 @@ int update_task(sqlite3 *db, int argc, char** argv){ task->table = "tasks"; parse_args(argc, argv, task); - // TODO this can definatly be made into one func with all the other updates + // TODO this can definitely be made into one func with all the other updates // no v2s allowed if ( gen_sql_update_stmt_v2(db, &out_stmt, task) ){ free(task); diff --git a/src/dodo.schema b/src/dodo.schema index a62c708..28e16f9 100644 --- a/src/dodo.schema +++ b/src/dodo.schema @@ -1,6 +1,6 @@ CREATE TABLE tasks( task_id INTEGER PRIMARY KEY, - title TEXT NOT NULL UNIQUE, + title TEXT NOT NULL, active_id INTEGER, status TEXT NOT NULL DEFAULT 'backlog', creation_date DATE DEFAULT (date('now')),