Removed table prop from struct
This commit is contained in:
parent
2524b1ed11
commit
b55a6bdb04
42
src/dodo.c
42
src/dodo.c
@ -30,7 +30,6 @@ int view_all(sqlite3 *db){
|
||||
}
|
||||
|
||||
void init_filtered_tasks(filtered_tasks* task){
|
||||
task->table = NULL;
|
||||
task->selected_columns = NULL;
|
||||
task->title = NULL;
|
||||
task->new_title = NULL;
|
||||
@ -47,11 +46,11 @@ int gen_sql_update_stmt_v2(sqlite3 *db, sqlite3_stmt** out_stmt, filtered_tasks*
|
||||
|
||||
if (task->new_title != NULL && task->due_date != NULL){
|
||||
// TODO: we might want to have a function that builds the final sql_query
|
||||
snprintf(sql_query, SQLQUERY_MAX, "UPDATE %s SET title='%s', due_date='%s' WHERE title='%s' OR active_id='%d'", task->table, task->new_title, task->due_date, task->title, task->active_id);
|
||||
snprintf(sql_query, SQLQUERY_MAX, "UPDATE tasks SET title='%s', due_date='%s' WHERE title='%s' OR active_id='%d'", task->new_title, task->due_date, task->title, task->active_id);
|
||||
}
|
||||
else if (task->new_title != NULL){
|
||||
snprintf(sql_query, SQLQUERY_MAX, "UPDATE %s SET title='%s' WHERE title='%s' OR active_id='%d'",
|
||||
task->table, task->new_title, task->title, task->active_id);
|
||||
snprintf(sql_query, SQLQUERY_MAX, "UPDATE tasks SET title='%s' WHERE title='%s' OR active_id='%d'",
|
||||
task->new_title, task->title, task->active_id);
|
||||
}
|
||||
else{
|
||||
return -1;
|
||||
@ -72,12 +71,17 @@ int gen_sql_update_stmt(sqlite3 *db, sqlite3_stmt** out_stmt, filtered_tasks* ta
|
||||
char sql_query[SQLQUERY_MAX];
|
||||
int rc = 0;
|
||||
|
||||
if (task->status != NULL){
|
||||
snprintf(sql_query, SQLQUERY_MAX, "UPDATE %s SET status='%s' WHERE title='%s' OR active_id='%d'",
|
||||
task->table, task->status, task->title, task->active_id);
|
||||
|
||||
if (task->new_title != NULL && task->due_date != NULL){
|
||||
// TODO: we might want to have a function that builds the final sql_query
|
||||
snprintf(sql_query, SQLQUERY_MAX, "UPDATE tasks SET title='%s', due_date='%s' WHERE title='%s' OR active_id='%d'", task->new_title, task->due_date, task->title, task->active_id);
|
||||
}
|
||||
else if (task->status != NULL){
|
||||
snprintf(sql_query, SQLQUERY_MAX, "UPDATE tasks SET status='%s' WHERE title='%s' OR active_id='%d'",
|
||||
task->status, task->title, task->active_id);
|
||||
}
|
||||
else{
|
||||
snprintf(sql_query, SQLQUERY_MAX, "UPDATE %s SET active_id='NULL',status='complete' WHERE title='%s' OR active_id='%d'", task->table, task->title, task->active_id);
|
||||
snprintf(sql_query, SQLQUERY_MAX, "UPDATE tasks SET active_id='NULL',status='complete' WHERE title='%s' OR active_id='%d'", task->title, task->active_id);
|
||||
}
|
||||
|
||||
rc = sqlite3_prepare_v2(db, sql_query, -1, out_stmt, NULL);
|
||||
@ -92,7 +96,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') AND active_id IS NOT NULL", task->table, task->title, task->active_id);
|
||||
snprintf(sql_query, SQLQUERY_MAX, "DELETE FROM tasks WHERE (title='%s' OR active_id='%d') AND active_id IS NOT NULL", 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")){
|
||||
@ -106,8 +110,8 @@ int gen_sql_insert_stmt(sqlite3 *db, sqlite3_stmt** out_stmt, filtered_tasks* ta
|
||||
char sql_query[SQLQUERY_MAX];
|
||||
int rc = 0;
|
||||
|
||||
snprintf(sql_query, SQLQUERY_MAX, "INSERT INTO %s %s VALUES %s",
|
||||
task->table, task->selected_columns, values);
|
||||
snprintf(sql_query, SQLQUERY_MAX, "INSERT INTO tasks %s VALUES %s",
|
||||
task->selected_columns, values);
|
||||
rc = sqlite3_prepare_v2(db, sql_query, -1, out_stmt, NULL);
|
||||
if (checksqlerr(rc, "prepare broken in gen_sql_insert_stmt")){
|
||||
return -1;
|
||||
@ -121,7 +125,7 @@ int gen_sql_select_stmt(sqlite3 *db, sqlite3_stmt** out_stmt, filtered_tasks* ta
|
||||
char sql_query[SQLQUERY_MAX];
|
||||
int rc = 0;
|
||||
|
||||
snprintf(sql_query, SQLQUERY_MAX, "SELECT %s FROM %s WHERE status='%s' AND active_id!='NULL' ORDER BY due_date NULLS LAST", task->selected_columns, task->table, task->status);
|
||||
snprintf(sql_query, SQLQUERY_MAX, "SELECT %s FROM tasks WHERE status='%s' AND active_id!='NULL' ORDER BY due_date NULLS LAST", task->selected_columns, task->status);
|
||||
rc = sqlite3_prepare_v2(db, sql_query, -1, out_stmt, NULL);
|
||||
if (checksqlerr(rc, "prepare broken in gen_sql_select_stmt")){
|
||||
return -1;
|
||||
@ -250,7 +254,6 @@ int parse_args(int argc, char** argv, filtered_tasks* task){
|
||||
// Get number of tasks from tasks table give status
|
||||
int get_num_rows(sqlite3 *db, char* table, char* status){
|
||||
filtered_tasks* task = malloc(sizeof(filtered_tasks));
|
||||
task->table = table;
|
||||
task->status = status;
|
||||
task->selected_columns = "COUNT(*)";
|
||||
sqlite3_stmt *out_stmt;
|
||||
@ -290,10 +293,11 @@ int display_task_list(int start_col, sqlite3 *db, filtered_tasks* task){
|
||||
const unsigned char* col_val;
|
||||
const unsigned char* col_name;
|
||||
sqlite3_stmt* out_stmt;
|
||||
char* table = "tasks";
|
||||
|
||||
|
||||
// Get the number of rows in current task list
|
||||
num_rows = get_num_rows(db, task->table, task->status);
|
||||
num_rows = get_num_rows(db, table, task->status);
|
||||
// Then keep track of the furthest down we go
|
||||
if (num_rows > max_rows){
|
||||
max_rows = num_rows;
|
||||
@ -326,11 +330,13 @@ int display_task_list(int start_col, sqlite3 *db, filtered_tasks* task){
|
||||
}
|
||||
print_fixed_width(col_val, fixed_width);
|
||||
}
|
||||
// end
|
||||
|
||||
// move down one and over to the start of the current task column
|
||||
printf("\n");
|
||||
// end
|
||||
X_goright(start_col);
|
||||
}
|
||||
|
||||
// reset to the beginning of the line
|
||||
printf("\r");
|
||||
|
||||
@ -364,7 +370,6 @@ int view_tasks(sqlite3 *db){
|
||||
// TODO check that malloc is ok
|
||||
|
||||
init_filtered_tasks(tasks);
|
||||
tasks->table = "tasks";
|
||||
tasks->selected_columns = "active_id, title, due_date";
|
||||
|
||||
// Print Heading
|
||||
@ -404,7 +409,6 @@ int add_new_task(sqlite3 *db, int argc, char** argv){
|
||||
filtered_tasks* task = malloc(sizeof(filtered_tasks));
|
||||
|
||||
init_filtered_tasks(task);
|
||||
task->table = "tasks";
|
||||
|
||||
parse_args(argc, argv, task);
|
||||
|
||||
@ -436,7 +440,6 @@ int update_task_status(sqlite3 *db, int argc, char** argv){
|
||||
filtered_tasks* task = malloc(sizeof(filtered_tasks));
|
||||
|
||||
init_filtered_tasks(task);
|
||||
task->table = "tasks";
|
||||
|
||||
parse_args(argc, argv, task);
|
||||
|
||||
@ -465,7 +468,6 @@ int complete_task(sqlite3 *db, int argc, char** argv){
|
||||
filtered_tasks* task = malloc(sizeof(filtered_tasks));
|
||||
|
||||
init_filtered_tasks(task);
|
||||
task->table = "tasks";
|
||||
|
||||
parse_args(argc, argv, task);
|
||||
if ( gen_sql_update_stmt(db, &out_stmt, task) ){
|
||||
@ -492,7 +494,6 @@ int update_task(sqlite3 *db, int argc, char** argv){
|
||||
|
||||
init_filtered_tasks(task);
|
||||
|
||||
task->table = "tasks";
|
||||
|
||||
parse_args(argc, argv, task);
|
||||
// TODO this can definitely be made into one func with all the other updates
|
||||
@ -521,7 +522,6 @@ int del_task(sqlite3 *db, int argc, char** argv){
|
||||
|
||||
init_filtered_tasks(task);
|
||||
|
||||
task->table = "tasks";
|
||||
|
||||
parse_args(argc, argv, task);
|
||||
if ( gen_sql_delete_stmt(db, &out_stmt, task) ){
|
||||
|
@ -12,7 +12,7 @@
|
||||
#define FIXED_MAX_WIDTH (FIXED_COLUMN_WIDTH)
|
||||
#define TODAY_COL_START -1
|
||||
#define BACKLOG_COL_START (FIXED_COLUMN_WIDTH + 1)
|
||||
#define BLOCKED_COL_START ( (2 * FIXED_COLUMN_WIDTH) + 1)
|
||||
#define BLOCKED_COL_START ( 2 * (FIXED_COLUMN_WIDTH + 1) )
|
||||
|
||||
// TODO maybe I should make another module that is strictly
|
||||
|
||||
@ -24,7 +24,6 @@ typedef struct{
|
||||
|
||||
// Filters for sql selection
|
||||
typedef struct {
|
||||
char *table;
|
||||
char *selected_columns;
|
||||
char *title;
|
||||
char *new_title;
|
||||
|
Loading…
Reference in New Issue
Block a user