Fixed bug that was looking for NULL instead of nullterm

TODO: Should prob use pointers over strict arrays
This commit is contained in:
xavi 2024-09-17 21:39:54 -07:00
parent 62a1565137
commit fc8af9a53c

View File

@ -32,11 +32,11 @@ int gen_sql_update_stmt_v2(sqlite3 *db, sqlite3_stmt** out_stmt, char* table, ch
char sql_query[SQLQUERY_MAX];
int rc = 0;
if (new_title != NULL && new_due_date != NULL){
if (new_title[0] != '\0' && new_due_date[0] != '\0'){
//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);
snprintf(sql_query, SQLQUERY_MAX, "UPDATE %s SET title='%s', due_date='%s' WHERE title='%s' OR active_id='%s'", table, new_title, new_due_date, title_or_active_id, title_or_active_id);
}
else if (new_title != NULL){
else if (new_title[0] != '\0'){
snprintf(sql_query, SQLQUERY_MAX, "UPDATE %s SET title='%s' WHERE title='%s' OR active_id='%s'", table, new_title, title_or_active_id, title_or_active_id);
}
else{
@ -227,21 +227,6 @@ int parse_args(int argc, char** argv, filtered_tasks* task){
return 0;
}
//int parse_args_v2(int argc, char** argv, char** title, char** new_title, char** new_due_date, char** new_project_tag){
// if ( argc > 2 ){
// *title = argv[2];
// }
// if ( argc > 3 ){
// *new_title = argv[3];
// }
// if ( argc > 4 ){
// *new_due_date = argv[4];
// }
// if ( argc > 5 ){
// *new_project_tag = argv[5];
// }
//}
// 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));
@ -481,8 +466,10 @@ int update_task(sqlite3 *db, int argc, char** argv){
int rc = 0;
sqlite3_stmt* out_stmt;
filtered_tasks* task = malloc(sizeof(filtered_tasks));
x_strcpy(task->table, "task", ARG_MAX);
task->new_title[0] = '\0';
task->due_date[0] = '\0';
x_strcpy(task->table, "tasks", ARG_MAX);
parse_args(argc, argv, task);
if ( gen_sql_update_stmt_v2(db, &out_stmt, task->table, task->new_title, task->due_date, task->project_tag, task->title) ){