Added del_task function
This commit is contained in:
parent
e8e73da981
commit
7d326f6057
61
src/dodo.c
61
src/dodo.c
@ -72,6 +72,20 @@ void display_heading(){
|
|||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int gen_sql_delete_stmt(sqlite3 *db, sqlite3_stmt** out_stmt, char* table, char* title){
|
||||||
|
char sql_query[SQLQUERY_MAX];
|
||||||
|
int rc = 0;
|
||||||
|
|
||||||
|
snprintf(sql_query, SQLQUERY_MAX, "DELETE FROM %s WHERE title='%s'", table, title);
|
||||||
|
|
||||||
|
rc = sqlite3_prepare_v2(db, sql_query, -1, out_stmt, NULL);
|
||||||
|
if (checksqlerr(rc, "prepare broken in gen_sql_insert_stmt")){
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int gen_sql_insert_stmt(sqlite3 *db, sqlite3_stmt** out_stmt, char* table, char* colnames, char* values){
|
int gen_sql_insert_stmt(sqlite3 *db, sqlite3_stmt** out_stmt, char* table, char* colnames, char* values){
|
||||||
char sql_query[SQLQUERY_MAX];
|
char sql_query[SQLQUERY_MAX];
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
@ -81,6 +95,8 @@ int gen_sql_insert_stmt(sqlite3 *db, sqlite3_stmt** out_stmt, char* table, char*
|
|||||||
if (checksqlerr(rc, "prepare broken in gen_sql_insert_stmt")){
|
if (checksqlerr(rc, "prepare broken in gen_sql_insert_stmt")){
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate the sql statement by giving the columns, table, and current task list wanted
|
// Generate the sql statement by giving the columns, table, and current task list wanted
|
||||||
@ -188,19 +204,39 @@ int display_task_list(int start_col, sqlite3 *db, char* colnames, char* table, c
|
|||||||
// due date passed as NULL if for delete
|
// due date passed as NULL if for delete
|
||||||
// TODO input validation for strings implement in strings!
|
// TODO input validation for strings implement in strings!
|
||||||
int parse_args(int argc, char** argv, char** title, char** due_date){
|
int parse_args(int argc, char** argv, char** title, char** due_date){
|
||||||
if ( argc > 1 ){
|
if ( argc > 2 ){
|
||||||
*title = argv[2];
|
*title = argv[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( argc > 2 ){
|
if ( argc > 3 ){
|
||||||
*due_date = argv[3];
|
*due_date = argv[3];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int del_task(sqlite3 *db, int argc, char** argv){
|
||||||
|
int rc = 0;
|
||||||
|
char* table = "tasks";
|
||||||
|
char* title;
|
||||||
|
sqlite3_stmt* out_stmt;
|
||||||
|
|
||||||
|
parse_args(argc, argv, &title, NULL);
|
||||||
|
if ( gen_sql_delete_stmt(db, &out_stmt, table, title) ){
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ( rc = sqlite3_step(out_stmt) ) == SQLITE_DONE){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
checksqlerr(rc, "broken in add_new_task");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// TODO: the way this ensures that we are only passing in
|
// TODO: the way this ensures that we are only passing in
|
||||||
// valid inputs is stupid and ugly FIX
|
// valid inputs is stupid and ugly FIX
|
||||||
int add_task(sqlite3 *db, int argc, char** argv){
|
int add_new_task(sqlite3 *db, int argc, char** argv){
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
char* table = "tasks";
|
char* table = "tasks";
|
||||||
char* title;
|
char* title;
|
||||||
@ -225,13 +261,13 @@ int add_task(sqlite3 *db, int argc, char** argv){
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
checksqlerr(rc, "broken in add_task");
|
checksqlerr(rc, "broken in add_new_task");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print kanban table
|
// Print kanban table
|
||||||
// All lists with task name and due date
|
// All lists with task name and due date
|
||||||
int view(sqlite3 *db){
|
int view_tasks(sqlite3 *db){
|
||||||
char* table = "tasks";
|
char* table = "tasks";
|
||||||
char* status = "today";
|
char* status = "today";
|
||||||
char* colnames = "title,due_date";
|
char* colnames = "title,due_date";
|
||||||
@ -267,18 +303,21 @@ int main( int argc, char **argv ){
|
|||||||
|
|
||||||
rc = opendb(&db, filename);
|
rc = opendb(&db, filename);
|
||||||
if ( argv[1] ){
|
if ( argv[1] ){
|
||||||
if (argv[1][0] == 'b'){
|
if (argv[1][0] == 'v'){
|
||||||
rc = view(db);
|
rc = view_tasks(db);
|
||||||
|
}
|
||||||
|
else if ( argv[1][0] == 'n'){
|
||||||
|
rc = add_new_task(db,argc,argv);
|
||||||
|
}
|
||||||
|
else if ( argv[1][0] == 'd'){
|
||||||
|
rc = del_task(db,argc,argv);
|
||||||
}
|
}
|
||||||
else if ( argv[1][0] == 'a'){
|
else if ( argv[1][0] == 'a'){
|
||||||
rc = add_task(db,argc,argv);
|
|
||||||
}
|
|
||||||
else if ( argv[1][0] == 'v'){
|
|
||||||
rc = view_all(db);
|
rc = view_all(db);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
rc = view(db);
|
rc = view_tasks(db);
|
||||||
}
|
}
|
||||||
|
|
||||||
sqlite3_close(db);
|
sqlite3_close(db);
|
||||||
|
Loading…
Reference in New Issue
Block a user