diff --git a/src/main/db.c b/src/main/db.c index 097ace2..76ca3a6 100644 --- a/src/main/db.c +++ b/src/main/db.c @@ -59,7 +59,7 @@ sqlite3* get_db() { "CREATE TABLE tasks ( \ id INTEGER PRIMARY KEY,\ text TEXT NOT NULL,\ - category TEXT DEFAULT '', \ + category TEXT DEFAULT NULL, \ done INTEGER, \ due_to INTEGER \ );", @@ -202,8 +202,12 @@ void get_task(int id, task_t* t) { strcpy(t->text, text); char* category = (char*)sqlite3_column_text(stmt, 4); - t->category = malloc(sizeof(char)*(strlen(category)+1)); - strcpy(t->category, category); + if (category) { + t->category = malloc(sizeof(char)*(strlen(category)+1)); + strcpy(t->category, category); + } else { + t->category = NULL; + } } sqlCheck( sqlite3_finalize(stmt) ); @@ -238,8 +242,13 @@ task_list_t* get_task_list(char* input_category, bool include_completed) { strcpy(t.text, text); char* category = (char*)sqlite3_column_text(stmt, 4); - t.category = malloc(sizeof(char)*(strlen(category)+1)); - strcpy(t.category, category); + if (category) { + t.category = malloc(sizeof(char)*(strlen(category)+1)); + strcpy(t.category, category); + } else { + t.category = NULL; + } + task_list_t* cur = malloc(sizeof(task_list_t)); // Add the parsed task to the beginning of the list cur->task = t; diff --git a/src/main/include/config.h b/src/main/include/config.h index 855f73b..eb1bf8e 100644 --- a/src/main/include/config.h +++ b/src/main/include/config.h @@ -1,7 +1,7 @@ #ifndef DEF_CONFIG_H #define DEF_CONFIG_H -#define VERSION "1.2.1" +#define VERSION "1.3.0" // By default, $HOME/.config/takl.sqlite3 is used. You can change this behaviour here //#define DB_FILE "takl.sqlite3"