Added ability to pass new task from cli, TODO:it's really bad

This commit is contained in:
xavi 2024-09-06 11:27:52 -07:00
parent 43323dbf9b
commit 53a5c910b5

View File

@ -5,6 +5,7 @@
#include "x_curses.h"
#define SQLQUERY_MAX 100
#define ARG_MAX 100
#define TODAY_COL_START -1
#define BACKLOG_COL_START 33
#define BLOCKED_COL_START 66
@ -180,40 +181,71 @@ int display_task_list(int start_col, sqlite3 *db, char* colnames, char* table, c
return 0;
}
int add_task(sqlite3 *db){
// pass in the args and return the title and due date
// due date passed as NULL if for delete
// TODO input validation for strings implement in strings!
int arg_parser(int argc, char** argv, char** title, char** due_date){
if ( argc > 1 ){
*title = argv[2];
}
if ( argc > 2 ){
*due_date = argv[3];
}
}
int add_task(sqlite3 *db, int argc, char** argv){
int rc = 0;
char* table = "tasks";
char* status = "today";
// Format Col names like this (col1, col2, col3)
char* title;
char* due_date;
char* colnames = "(title, due_date)";
// Format values like this
// For first row For second row For third row
// (col1val, col2val, col3val), (col1val, col2val, col3val), (col1val, col2val, col3val)
char* values = "('weeeeeeep',2024-09-05)";
char values[100];
sqlite3_stmt* out_stmt;
arg_parser(argc, argv, &title, &due_date);
snprintf(values, 100, "('%s', '%s')", title, due_date);
if ( gen_sql_insert_stmt(db, &out_stmt, table, colnames, values) ){
return -1;
}
if ( ( rc = sqlite3_step(out_stmt) ) == SQLITE_DONE){
return 0;
}
checksqlerr(rc, "broken in add_task");
return 1;
// Format Col names like this (col1, col2, col3)
//char* colnames = "(title, due_date)";
// Format values like this
// For first row For second row For third row
// (col1val, col2val, col3val), (col1val, col2val, col3val), (col1val, col2val, col3val)
// char* values[ARG_MAX];
// sqlite3_stmt* out_stmt;
//
//
// if ( gen_sql_insert_stmt(db, &out_stmt, table, colnames, values) ){
// return -1;
// }
//
// if ( ( rc = sqlite3_step(out_stmt) ) == SQLITE_DONE){
// return 0;
// }
//
// checksqlerr(rc, "broken in add_task");
// return 1;
}
// Print kanban table
// All lists with task name and due date
// TODO just gotta use snprintf because can't bind column or table names
int view(sqlite3 *db){
char* table = "tasks";
char* status = "today";
char* colnames = "title,creation_date";
char* colnames = "title,due_date";
// Print Heading
display_heading();
@ -249,10 +281,10 @@ int main( int argc, char **argv ){
if (argv[1][0] == 'b'){
rc = view(db);
}
else if ( argv[1][0] == 'c'){
rc = add_task(db);
}
else if ( argv[1][0] == 'a'){
rc = add_task(db,argc,argv);
}
else if ( argv[1][0] == 'v'){
rc = view_all(db);
}
}