Compare commits
3 Commits
df50e34958
...
4636a19796
Author | SHA1 | Date | |
---|---|---|---|
4636a19796 | |||
20fdead266 | |||
24e7dc3ae7 |
77
src/dodo.c
77
src/dodo.c
@ -32,12 +32,13 @@ int gen_sql_update_stmt_v2(sqlite3 *db, sqlite3_stmt** out_stmt, filtered_tasks*
|
|||||||
char sql_query[SQLQUERY_MAX];
|
char sql_query[SQLQUERY_MAX];
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
|
||||||
if (task->new_title[0] != '\0' && task->due_date[0] != '\0'){
|
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);
|
//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='%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[0] != '\0'){
|
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 %s SET title='%s' WHERE title='%s' OR active_id='%d'",
|
||||||
|
task->table, task->new_title, task->title, task->active_id);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
return -1;
|
return -1;
|
||||||
@ -57,8 +58,9 @@ int gen_sql_update_stmt(sqlite3 *db, sqlite3_stmt** out_stmt, filtered_tasks* ta
|
|||||||
char sql_query[SQLQUERY_MAX];
|
char sql_query[SQLQUERY_MAX];
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
|
||||||
if (task->status[0] != '\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);
|
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);
|
||||||
}
|
}
|
||||||
else{
|
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 %s SET active_id='NULL',status='complete' WHERE title='%s' OR active_id='%d'", task->table, task->title, task->active_id);
|
||||||
@ -77,7 +79,8 @@ int gen_sql_delete_stmt(sqlite3 *db, sqlite3_stmt** out_stmt, filtered_tasks* ta
|
|||||||
char sql_query[SQLQUERY_MAX];
|
char sql_query[SQLQUERY_MAX];
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
|
||||||
snprintf(sql_query, SQLQUERY_MAX, "DELETE FROM %s WHERE title='%s' OR active_id='%d'", task->table, task->title, task->active_id);
|
snprintf(sql_query, SQLQUERY_MAX, "DELETE FROM %s WHERE title='%s' OR active_id='%d'",
|
||||||
|
task->table, task->title, task->active_id);
|
||||||
|
|
||||||
rc = sqlite3_prepare_v2(db, sql_query, -1, out_stmt, NULL);
|
rc = sqlite3_prepare_v2(db, sql_query, -1, out_stmt, NULL);
|
||||||
if (checksqlerr(rc, "prepare broken in gen_sql_insert_stmt")){
|
if (checksqlerr(rc, "prepare broken in gen_sql_insert_stmt")){
|
||||||
@ -91,7 +94,8 @@ int gen_sql_insert_stmt(sqlite3 *db, sqlite3_stmt** out_stmt, filtered_tasks* ta
|
|||||||
char sql_query[SQLQUERY_MAX];
|
char sql_query[SQLQUERY_MAX];
|
||||||
int rc = 0;
|
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 %s %s VALUES %s",
|
||||||
|
task->table, task->selected_columns, values);
|
||||||
rc = sqlite3_prepare_v2(db, sql_query, -1, out_stmt, NULL);
|
rc = sqlite3_prepare_v2(db, sql_query, -1, out_stmt, NULL);
|
||||||
if (checksqlerr(rc, "prepare broken in gen_sql_insert_stmt")){
|
if (checksqlerr(rc, "prepare broken in gen_sql_insert_stmt")){
|
||||||
return -1;
|
return -1;
|
||||||
@ -203,26 +207,26 @@ 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 ){
|
||||||
x_strcpy(task->title, argv[2], ARG_MAX);
|
task->title = argv[2];
|
||||||
task->active_id = atoi(argv[2]);
|
task->active_id = atoi(argv[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( argc > 3 ){
|
if ( argc > 3 ){
|
||||||
if ( x_strcmp(argv[1], "update") ){
|
if ( x_strcmp(argv[1], "update") ){
|
||||||
x_strcpy(task->due_date, argv[3], ARG_MAX);
|
task->due_date = argv[3];
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
x_strcpy(task->new_title, argv[3], ARG_MAX);
|
task->new_title = argv[3];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( argc > 4 ){
|
if ( argc > 4 ){
|
||||||
x_strcpy(task->due_date, argv[4], ARG_MAX);
|
task->due_date = argv[3];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( argc > 5 ){
|
if ( argc > 5 ){
|
||||||
x_strcpy(task->project_tag, argv[5], ARG_MAX);
|
task->project_tag = argv[5];
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -231,9 +235,9 @@ int parse_args(int argc, char** argv, filtered_tasks* task){
|
|||||||
// Get number of tasks from tasks table give status
|
// Get number of tasks from tasks table give status
|
||||||
int get_num_rows(sqlite3 *db, char* table, char* status){
|
int get_num_rows(sqlite3 *db, char* table, char* status){
|
||||||
filtered_tasks* task = malloc(sizeof(filtered_tasks));
|
filtered_tasks* task = malloc(sizeof(filtered_tasks));
|
||||||
x_strcpy(task->table, table, ARG_MAX);
|
task->table = table;
|
||||||
x_strcpy(task->status, status, ARG_MAX);
|
task->status = status;
|
||||||
x_strcpy(task->selected_columns, "COUNT(*)", ARG_MAX);
|
task->selected_columns = "COUNT(*)";
|
||||||
sqlite3_stmt *out_stmt;
|
sqlite3_stmt *out_stmt;
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
|
||||||
@ -341,28 +345,28 @@ int view_tasks(sqlite3 *db){
|
|||||||
// Set the table and cols to be printed
|
// Set the table and cols to be printed
|
||||||
filtered_tasks* tasks = malloc(sizeof(filtered_tasks));
|
filtered_tasks* tasks = malloc(sizeof(filtered_tasks));
|
||||||
// TODO check that malloc is ok
|
// TODO check that malloc is ok
|
||||||
x_strcpy(tasks->table, "tasks", ARG_MAX);
|
tasks->table = "tasks";
|
||||||
x_strcpy(tasks->selected_columns, "active_id, title, due_date", ARG_MAX);
|
tasks->selected_columns = "active_id, title, due_date";
|
||||||
|
|
||||||
// Print Heading
|
// Print Heading
|
||||||
display_heading();
|
display_heading();
|
||||||
|
|
||||||
// Print "today" tasks
|
// Print "today" tasks
|
||||||
x_strcpy(tasks->status, "today", ARG_MAX);
|
tasks->status = "today";
|
||||||
if ( display_task_list(TODAY_COL_START, db, tasks) ){
|
if ( display_task_list(TODAY_COL_START, db, tasks) ){
|
||||||
free(tasks);
|
free(tasks);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print "backlog" tasks
|
// Print "backlog" tasks
|
||||||
x_strcpy(tasks->status, "backlog", ARG_MAX);
|
tasks->status = "backlog";
|
||||||
if ( display_task_list(BACKLOG_COL_START, db, tasks) ){
|
if ( display_task_list(BACKLOG_COL_START, db, tasks) ){
|
||||||
free(tasks);
|
free(tasks);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print "blocked" tasks
|
// Print "blocked" tasks
|
||||||
x_strcpy(tasks->status, "blocked", ARG_MAX);
|
tasks->status = "blocked";
|
||||||
if ( display_task_list(BLOCKED_COL_START, db, tasks) ){
|
if ( display_task_list(BLOCKED_COL_START, db, tasks) ){
|
||||||
free(tasks);
|
free(tasks);
|
||||||
return -1;
|
return -1;
|
||||||
@ -381,18 +385,19 @@ int add_new_task(sqlite3 *db, int argc, char** argv){
|
|||||||
sqlite3_stmt* out_stmt;
|
sqlite3_stmt* out_stmt;
|
||||||
|
|
||||||
filtered_tasks* task = malloc(sizeof(filtered_tasks));
|
filtered_tasks* task = malloc(sizeof(filtered_tasks));
|
||||||
x_strcpy(task->table, "tasks", ARG_MAX);
|
task->table = "tasks";
|
||||||
task->title[0] = '\0';
|
|
||||||
task->due_date[0] = '\0';
|
task->title = NULL;
|
||||||
|
task->due_date = NULL;
|
||||||
|
|
||||||
parse_args(argc, argv, task);
|
parse_args(argc, argv, task);
|
||||||
|
|
||||||
if ( task->title[0] != '\0' ){
|
if ( task->title != NULL ){
|
||||||
if ( task->due_date[0] != '\0' ){
|
if ( task->due_date != NULL ){
|
||||||
x_strcpy(task->selected_columns, "(title, due_date)", ARG_MAX);
|
task->selected_columns = "(title, due_date)";
|
||||||
snprintf(values, ARG_MAX, "('%s', '%s')", task->title, task->due_date);
|
snprintf(values, ARG_MAX, "('%s', '%s')", task->title, task->due_date);
|
||||||
}else{
|
}else{
|
||||||
x_strcpy(task->selected_columns, "(title)", ARG_MAX);
|
task->selected_columns = "(title)";
|
||||||
snprintf(values, ARG_MAX, "('%s')", task->title);
|
snprintf(values, ARG_MAX, "('%s')", task->title);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -414,13 +419,13 @@ int update_task_status(sqlite3 *db, int argc, char** argv){
|
|||||||
sqlite3_stmt* out_stmt;
|
sqlite3_stmt* out_stmt;
|
||||||
filtered_tasks* task = malloc(sizeof(filtered_tasks));
|
filtered_tasks* task = malloc(sizeof(filtered_tasks));
|
||||||
|
|
||||||
task->status[0] = '\0';
|
task->status = NULL;
|
||||||
x_strcpy(task->table, "tasks", ARG_MAX);
|
task->table = "tasks";
|
||||||
|
|
||||||
// TODO: this is not just title but also active ID so fix this
|
// TODO: this is not just title but also active ID so fix this
|
||||||
parse_args(argc, argv, task);
|
parse_args(argc, argv, task);
|
||||||
|
|
||||||
x_strcpy(task->status, argv[1], ARG_MAX);
|
task->status = argv[1];
|
||||||
if ( gen_sql_update_stmt(db, &out_stmt, task) ){
|
if ( gen_sql_update_stmt(db, &out_stmt, task) ){
|
||||||
free(task);
|
free(task);
|
||||||
return -1;
|
return -1;
|
||||||
@ -444,8 +449,8 @@ int complete_task(sqlite3 *db, int argc, char** argv){
|
|||||||
sqlite3_stmt* out_stmt;
|
sqlite3_stmt* out_stmt;
|
||||||
filtered_tasks* task = malloc(sizeof(filtered_tasks));
|
filtered_tasks* task = malloc(sizeof(filtered_tasks));
|
||||||
|
|
||||||
task->status[0] = '\0';
|
task->status = NULL;
|
||||||
x_strcpy(task->table, "tasks", ARG_MAX);
|
task->table = "tasks";
|
||||||
|
|
||||||
parse_args(argc, argv, task);
|
parse_args(argc, argv, task);
|
||||||
if ( gen_sql_update_stmt(db, &out_stmt, task) ){
|
if ( gen_sql_update_stmt(db, &out_stmt, task) ){
|
||||||
@ -471,9 +476,9 @@ int update_task(sqlite3 *db, int argc, char** argv){
|
|||||||
sqlite3_stmt* out_stmt;
|
sqlite3_stmt* out_stmt;
|
||||||
filtered_tasks* task = malloc(sizeof(filtered_tasks));
|
filtered_tasks* task = malloc(sizeof(filtered_tasks));
|
||||||
|
|
||||||
task->new_title[0] = '\0';
|
task->new_title = NULL;
|
||||||
task->due_date[0] = '\0';
|
task->due_date = NULL;
|
||||||
x_strcpy(task->table, "tasks", ARG_MAX);
|
task->table = "tasks";
|
||||||
|
|
||||||
parse_args(argc, argv, task);
|
parse_args(argc, argv, task);
|
||||||
if ( gen_sql_update_stmt_v2(db, &out_stmt, task) ){
|
if ( gen_sql_update_stmt_v2(db, &out_stmt, task) ){
|
||||||
@ -499,7 +504,7 @@ int del_task(sqlite3 *db, int argc, char** argv){
|
|||||||
filtered_tasks* task = malloc(sizeof(filtered_tasks));
|
filtered_tasks* task = malloc(sizeof(filtered_tasks));
|
||||||
|
|
||||||
task->active_id = 0;
|
task->active_id = 0;
|
||||||
x_strcpy(task->table, "tasks", ARG_MAX);
|
task->table = "tasks";
|
||||||
|
|
||||||
parse_args(argc, argv, task);
|
parse_args(argc, argv, task);
|
||||||
if ( gen_sql_delete_stmt(db, &out_stmt, task) ){
|
if ( gen_sql_delete_stmt(db, &out_stmt, task) ){
|
||||||
|
19
src/dodo.h
19
src/dodo.h
@ -4,7 +4,7 @@
|
|||||||
#define SQLQUERY_MAX 400
|
#define SQLQUERY_MAX 400
|
||||||
#define ARG_MAX 100
|
#define ARG_MAX 100
|
||||||
#define NUM_TASK_LISTS 3
|
#define NUM_TASK_LISTS 3
|
||||||
#define FIXED_TITLE_WIDTH 21
|
#define FIXED_TITLE_WIDTH 20
|
||||||
#define FIXED_DATE_WIDTH 12
|
#define FIXED_DATE_WIDTH 12
|
||||||
#define FIXED_ID_WIDTH 4
|
#define FIXED_ID_WIDTH 4
|
||||||
#define FIXED_COLUMN_WIDTH (FIXED_ID_WIDTH + FIXED_TITLE_WIDTH +FIXED_DATE_WIDTH)
|
#define FIXED_COLUMN_WIDTH (FIXED_ID_WIDTH + FIXED_TITLE_WIDTH +FIXED_DATE_WIDTH)
|
||||||
@ -12,7 +12,7 @@
|
|||||||
#define FIXED_MAX_WIDTH (FIXED_COLUMN_WIDTH)
|
#define FIXED_MAX_WIDTH (FIXED_COLUMN_WIDTH)
|
||||||
#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 (FIXED_COLUMN_WIDTH + 1)
|
#define BLOCKED_COL_START ( (2 * FIXED_COLUMN_WIDTH) + 1)
|
||||||
#define DUEPARSE_SIZE 4
|
#define DUEPARSE_SIZE 4
|
||||||
|
|
||||||
typedef struct{
|
typedef struct{
|
||||||
@ -23,15 +23,14 @@ typedef struct{
|
|||||||
|
|
||||||
// Filters for sql selection
|
// Filters for sql selection
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char table[ARG_MAX];
|
char *table;
|
||||||
char selected_columns[ARG_MAX];
|
char *selected_columns;
|
||||||
char title[ARG_MAX];
|
char *title;
|
||||||
char new_title[ARG_MAX];
|
char *new_title;
|
||||||
int active_id;
|
int active_id;
|
||||||
char status[ARG_MAX];
|
char *status;
|
||||||
char project_tag[ARG_MAX];
|
char *project_tag;
|
||||||
char creation_date[ARG_MAX];
|
char *due_date;
|
||||||
char due_date[ARG_MAX];
|
|
||||||
}filtered_tasks;
|
}filtered_tasks;
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user