Added filtered_tasks constructor

This commit is contained in:
xavi 2024-09-20 22:12:45 -07:00
parent 5b5b36c041
commit dbc57e38c9
2 changed files with 26 additions and 11 deletions

View File

@ -29,8 +29,16 @@ int view_all(sqlite3 *db){
return rc;
}
// sql generators TODO: might be able to boil this down to 1 func
void init_filtered_tasks(filtered_tasks* task){
task->table = NULL;
task->selected_columns = NULL;
task->title = NULL;
task->new_title = NULL;
task->active_id = -1;
task->status = NULL;
task->project_tag = NULL;
task->due_date = NULL;
}
// TODO: this really needs to only be one function with update_stmt()
int gen_sql_update_stmt_v2(sqlite3 *db, sqlite3_stmt** out_stmt, filtered_tasks* task){
@ -352,6 +360,8 @@ int view_tasks(sqlite3 *db){
// Set the table and cols to be printed
filtered_tasks* tasks = malloc(sizeof(filtered_tasks));
// TODO check that malloc is ok
init_filtered_tasks(tasks);
tasks->table = "tasks";
tasks->selected_columns = "active_id, title, due_date";
@ -390,10 +400,9 @@ int add_new_task(sqlite3 *db, int argc, char** argv){
sqlite3_stmt* out_stmt;
filtered_tasks* task = malloc(sizeof(filtered_tasks));
task->table = "tasks";
task->title = NULL;
task->due_date = NULL;
init_filtered_tasks(task);
task->table = "tasks";
parse_args(argc, argv, task);
@ -424,7 +433,7 @@ int update_task_status(sqlite3 *db, int argc, char** argv){
sqlite3_stmt* out_stmt;
filtered_tasks* task = malloc(sizeof(filtered_tasks));
task->status = NULL;
init_filtered_tasks(task);
task->table = "tasks";
parse_args(argc, argv, task);
@ -453,7 +462,7 @@ int complete_task(sqlite3 *db, int argc, char** argv){
sqlite3_stmt* out_stmt;
filtered_tasks* task = malloc(sizeof(filtered_tasks));
task->status = NULL;
init_filtered_tasks(task);
task->table = "tasks";
parse_args(argc, argv, task);
@ -478,9 +487,9 @@ int update_task(sqlite3 *db, int argc, char** argv){
int rc = 0;
sqlite3_stmt* out_stmt;
filtered_tasks* task = malloc(sizeof(filtered_tasks));
task->new_title = NULL;
task->due_date = NULL;
init_filtered_tasks(task);
task->table = "tasks";
parse_args(argc, argv, task);
@ -508,7 +517,8 @@ int del_task(sqlite3 *db, int argc, char** argv){
sqlite3_stmt* out_stmt;
filtered_tasks* task = malloc(sizeof(filtered_tasks));
task->active_id = 0;
init_filtered_tasks(task);
task->table = "tasks";
parse_args(argc, argv, task);

View File

@ -14,6 +14,8 @@
#define BACKLOG_COL_START (FIXED_COLUMN_WIDTH + 1)
#define BLOCKED_COL_START ( (2 * FIXED_COLUMN_WIDTH) + 1)
// TODO maybe I should make another module that is strictly
typedef struct{
int year;
int month;
@ -37,6 +39,9 @@ typedef struct {
int callback(void *NotUsed, int argc, char **argv, char **azColName);
int view_all(sqlite3 *db);
// filtered_tasks constructor
void init_filtered_tasks(filtered_tasks* task);
// sql generators TODO: might be able to boil this down to 1 func
int gen_sql_update_stmt(sqlite3 *db, sqlite3_stmt** out_stmt, filtered_tasks* task);
int gen_sql_update_stmt_v2(sqlite3 *db, sqlite3_stmt** out_stmt, filtered_tasks* task);