Updated TODO notes and Added bad arg catch
This commit is contained in:
parent
4636a19796
commit
1229d88253
19
src/dodo.c
19
src/dodo.c
@ -28,12 +28,16 @@ int view_all(sqlite3 *db){
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// sql generators TODO: might be able to boil this down to 1 func
|
||||||
|
|
||||||
|
// 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){
|
int gen_sql_update_stmt_v2(sqlite3 *db, sqlite3_stmt** out_stmt, filtered_tasks* task){
|
||||||
char sql_query[SQLQUERY_MAX];
|
char sql_query[SQLQUERY_MAX];
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
|
||||||
if (task->new_title != NULL && task->due_date != NULL){
|
if (task->new_title != NULL && task->due_date != NULL){
|
||||||
//snprintf(sql_query, SQLQUERY_MAX, "UPDATE %s SET title='%s', due_date='%s', project_tag='%s' WHERE title='%s' OR active_id='%s'", table, status, title_or_active_id, title_or_active_id);
|
// 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 %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);
|
||||||
}
|
}
|
||||||
else if (task->new_title != NULL){
|
else if (task->new_title != NULL){
|
||||||
@ -45,6 +49,8 @@ int gen_sql_update_stmt_v2(sqlite3 *db, sqlite3_stmt** out_stmt, filtered_tasks*
|
|||||||
}
|
}
|
||||||
|
|
||||||
rc = sqlite3_prepare_v2(db, sql_query, -1, out_stmt, NULL);
|
rc = sqlite3_prepare_v2(db, sql_query, -1, out_stmt, NULL);
|
||||||
|
|
||||||
|
// TODO: Error checking is still pretty subpar
|
||||||
if (checksqlerr(rc, "prepare broken in gen_sql_insert_stmt")){
|
if (checksqlerr(rc, "prepare broken in gen_sql_insert_stmt")){
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -53,7 +59,6 @@ int gen_sql_update_stmt_v2(sqlite3 *db, sqlite3_stmt** out_stmt, filtered_tasks*
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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(sqlite3 *db, sqlite3_stmt** out_stmt, filtered_tasks* task){
|
||||||
char sql_query[SQLQUERY_MAX];
|
char sql_query[SQLQUERY_MAX];
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
@ -72,7 +77,6 @@ int gen_sql_update_stmt(sqlite3 *db, sqlite3_stmt** out_stmt, filtered_tasks* ta
|
|||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int gen_sql_delete_stmt(sqlite3 *db, sqlite3_stmt** out_stmt, filtered_tasks* task){
|
int gen_sql_delete_stmt(sqlite3 *db, sqlite3_stmt** out_stmt, filtered_tasks* task){
|
||||||
@ -118,6 +122,7 @@ int gen_sql_select_stmt(sqlite3 *db, sqlite3_stmt** out_stmt, filtered_tasks* ta
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: I think this needs a bit of a refactor not sure how
|
||||||
int checksqlerr(int rc, char *errmsg){
|
int checksqlerr(int rc, char *errmsg){
|
||||||
if( rc!=SQLITE_OK ){
|
if( rc!=SQLITE_OK ){
|
||||||
fprintf(stderr, "rc = %d\n", rc);
|
fprintf(stderr, "rc = %d\n", rc);
|
||||||
@ -207,6 +212,8 @@ void display_heading(){
|
|||||||
int parse_args(int argc, char** argv, filtered_tasks* task){
|
int parse_args(int argc, char** argv, filtered_tasks* task){
|
||||||
|
|
||||||
if ( argc > 2 ){
|
if ( argc > 2 ){
|
||||||
|
// TODO: We should do something about this ugly thing where we are setting
|
||||||
|
// active ID to any string passed
|
||||||
task->title = argv[2];
|
task->title = argv[2];
|
||||||
task->active_id = atoi(argv[2]);
|
task->active_id = atoi(argv[2]);
|
||||||
}
|
}
|
||||||
@ -376,8 +383,6 @@ int view_tasks(sqlite3 *db){
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: the way this ensures that we are only passing in
|
|
||||||
// valid inputs is stupid and ugly FIX
|
|
||||||
int add_new_task(sqlite3 *db, int argc, char** argv){
|
int add_new_task(sqlite3 *db, int argc, char** argv){
|
||||||
|
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
@ -422,7 +427,6 @@ int update_task_status(sqlite3 *db, int argc, char** argv){
|
|||||||
task->status = NULL;
|
task->status = NULL;
|
||||||
task->table = "tasks";
|
task->table = "tasks";
|
||||||
|
|
||||||
// TODO: this is not just title but also active ID so fix this
|
|
||||||
parse_args(argc, argv, task);
|
parse_args(argc, argv, task);
|
||||||
|
|
||||||
task->status = argv[1];
|
task->status = argv[1];
|
||||||
@ -470,7 +474,6 @@ int complete_task(sqlite3 *db, int argc, char** argv){
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO this can definatly be made into one func with all the other updates
|
|
||||||
int update_task(sqlite3 *db, int argc, char** argv){
|
int update_task(sqlite3 *db, int argc, char** argv){
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
sqlite3_stmt* out_stmt;
|
sqlite3_stmt* out_stmt;
|
||||||
@ -481,6 +484,8 @@ int update_task(sqlite3 *db, int argc, char** argv){
|
|||||||
task->table = "tasks";
|
task->table = "tasks";
|
||||||
|
|
||||||
parse_args(argc, argv, task);
|
parse_args(argc, argv, task);
|
||||||
|
// TODO this can definatly be made into one func with all the other updates
|
||||||
|
// no v2s allowed
|
||||||
if ( gen_sql_update_stmt_v2(db, &out_stmt, task) ){
|
if ( gen_sql_update_stmt_v2(db, &out_stmt, task) ){
|
||||||
free(task);
|
free(task);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -13,7 +13,6 @@
|
|||||||
#define TODAY_COL_START -1
|
#define TODAY_COL_START -1
|
||||||
#define BACKLOG_COL_START (FIXED_COLUMN_WIDTH + 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)
|
||||||
#define DUEPARSE_SIZE 4
|
|
||||||
|
|
||||||
typedef struct{
|
typedef struct{
|
||||||
int year;
|
int year;
|
||||||
|
@ -40,6 +40,10 @@ int main( int argc, char **argv ){
|
|||||||
else if (x_strcmp(argv[1], "update") == 0){
|
else if (x_strcmp(argv[1], "update") == 0){
|
||||||
rc = update_task(db,argc,argv);
|
rc = update_task(db,argc,argv);
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
|
printf("Unknown Argument:\n");
|
||||||
|
printf("Format: dodo [action] [task] [additional args]\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
rc = view_tasks(db);
|
rc = view_tasks(db);
|
||||||
|
Loading…
Reference in New Issue
Block a user