Compare commits
4 Commits
61e9ee7047
...
22e71dd40a
Author | SHA1 | Date | |
---|---|---|---|
22e71dd40a | |||
daabdcbfac | |||
bcf1c17bf7 | |||
1e1163b96a |
183
src/dodo.c
183
src/dodo.c
@ -4,6 +4,12 @@
|
||||
#include "x_string.h"
|
||||
#include "x_curses.h"
|
||||
|
||||
#define SQLQUERY_MAX 100
|
||||
#define TODAY_COL_START -1
|
||||
#define BACKLOG_COL_START 33
|
||||
#define BLOCKED_COL_START 66
|
||||
#define FIXED_WIDTH 19
|
||||
|
||||
int checksqlerr(int rc, char *errmsg){
|
||||
if( rc!=SQLITE_OK ){
|
||||
fprintf(stderr, "SQL error: %s\n", errmsg);
|
||||
@ -39,8 +45,9 @@ int callback(void *NotUsed, int argc, char **argv, char **azColName){
|
||||
}
|
||||
|
||||
// FOR DEBUG
|
||||
int view_all(sqlite3 *db, char *errmsg){
|
||||
int view_all(sqlite3 *db){
|
||||
int rc = 0;
|
||||
char* errmsg;
|
||||
|
||||
//rc = sqlite3_exec(db, "SELECT * FROM all_info;", print_select, 0, &errmsg);
|
||||
rc = sqlite3_exec(db, "SELECT * FROM tasks;", callback, 0, &errmsg);
|
||||
@ -63,36 +70,46 @@ int print_select(void *passed_col, int argc, char **argv, char **azColName){
|
||||
|
||||
// Print Heading TODO: obvi make this better
|
||||
void view_heading(){
|
||||
printf("%s%stitle due date%s", X_BOLD, X_UNDL, X_RST);
|
||||
printf(" %s%stitle due date%s", X_BOLD, X_UNDL, X_RST);
|
||||
printf(" %s%stitle due date%s", X_BOLD, X_UNDL, X_RST);
|
||||
printf("%s%stitle due date %s", X_BOLD, X_UNDL, X_RST);
|
||||
printf(" %s%stitle due date %s", X_BOLD, X_UNDL, X_RST);
|
||||
printf(" %s%stitle due date %s", X_BOLD, X_UNDL, X_RST);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
int print_select_test(sqlite3 *db, sqlite3_stmt* out_stmt, char* colnames, char* table, char* status){
|
||||
char *sql_query = "SELECT ? FROM ? WHERE status = ?";
|
||||
// Generate the sql statement by giving the columns, table, and current task list wanted
|
||||
// TODO make the stmt an arg pass and return an int
|
||||
// TODO ME THINKS THIS IS THE NEXT THING TO DO BECAUSE BREAKING EVERYTHING
|
||||
sqlite3_stmt *gen_sql_stmt(sqlite3 *db, char* colnames, char* table, char* status){
|
||||
char sql_query[SQLQUERY_MAX];
|
||||
int rc = 0;
|
||||
sqlite3_stmt *out_stmt;
|
||||
|
||||
snprintf(sql_query, SQLQUERY_MAX, "SELECT %s FROM %s WHERE status='%s'", colnames, table, status);
|
||||
rc = sqlite3_prepare_v2(db, sql_query, -1, &out_stmt, NULL);
|
||||
rc = sqlite3_bind_text(out_stmt, 1, colnames, -1, SQLITE_STATIC);
|
||||
rc = sqlite3_bind_text(out_stmt, 2, table, -1, SQLITE_STATIC);
|
||||
rc = sqlite3_bind_text(out_stmt, 3, status, -1, SQLITE_STATIC);
|
||||
if (checksqlerr(rc, "prepare broken in gen_sql_stmt")){
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return out_stmt;
|
||||
}
|
||||
|
||||
// Get number of tasks from tasks table give status
|
||||
// TODO: Gotta make the error checking not broken
|
||||
int get_num_rows(sqlite3 *db, char* table, char* status, char *errmsg){
|
||||
int get_num_rows(sqlite3 *db, char* table, char* status){
|
||||
char *sql_query = "SELECT COUNT(*) FROM tasks WHERE status = ?";
|
||||
sqlite3_stmt *out_stmt;
|
||||
int rc = 0;
|
||||
char *col_name = "COUNT(*)";
|
||||
|
||||
rc = sqlite3_prepare_v2(db, sql_query, -1, &out_stmt, NULL);
|
||||
checksqlerr(rc, errmsg);
|
||||
if ( ( out_stmt = gen_sql_stmt(db, col_name, table, status) ) == NULL ){
|
||||
return 1;
|
||||
}
|
||||
|
||||
//rc = sqlite3_prepare_v2(db, sql_query, -1, &out_stmt, NULL);
|
||||
//checksqlerr(rc, "prepare broken in get_num_rows");
|
||||
|
||||
rc = sqlite3_bind_text(out_stmt, 1, status, -1, SQLITE_STATIC);
|
||||
checksqlerr(rc, errmsg);
|
||||
checksqlerr(rc, "bind broken in get_num_rows");
|
||||
|
||||
while ( rc = sqlite3_step(out_stmt) == SQLITE_ROW ){
|
||||
return sqlite3_column_int(out_stmt, 0);
|
||||
@ -101,90 +118,116 @@ int get_num_rows(sqlite3 *db, char* table, char* status, char *errmsg){
|
||||
return 1;
|
||||
}
|
||||
|
||||
// TODO error checking needs done
|
||||
//int print_status_column(sqlite3 *db, char* table, char* status){
|
||||
// int rc = 0;
|
||||
// sqlite3_stmt *out_stmt;
|
||||
// char *sql_query = "SELECT title,due_date ? tasks WHERE status='?'";
|
||||
//
|
||||
// rc = sqlite3_prepare_v2(db, sql_query, -1, out_stmt, NULL);
|
||||
//
|
||||
// rc = sqlite3_bind_text(out_stmt, 1, table, -1, SQLITE_STATIC);
|
||||
// rc = sqlite3_bind_text(out_stmt, 2, status, -1, SQLITE_STATIC);
|
||||
//
|
||||
//
|
||||
//}
|
||||
// Print columns
|
||||
int print_fixed_width(const unsigned char* str){
|
||||
if (str){
|
||||
printf("%-*.*s", FIXED_WIDTH, FIXED_WIDTH, str);
|
||||
}else{
|
||||
printf("%-*.*s", FIXED_WIDTH, FIXED_WIDTH, "");
|
||||
}
|
||||
}
|
||||
|
||||
int display_task_list(int start_col, sqlite3 *db, char* colnames, char* table, char* status){
|
||||
static int max_rows = 0;
|
||||
int rc = 0;
|
||||
int i = 0;
|
||||
int num_rows = 0;
|
||||
int num_cols = 0;
|
||||
char* errmsg;
|
||||
const unsigned char* col_val;
|
||||
sqlite3_stmt* out_stmt;
|
||||
|
||||
// Start col for the current task list
|
||||
X_goright(start_col);
|
||||
|
||||
// Get the number of rows in current task list
|
||||
num_rows = get_num_rows(db, table, status);
|
||||
// Then keep track of the furthest down we go
|
||||
if (num_rows > max_rows){
|
||||
max_rows = num_rows;
|
||||
}
|
||||
|
||||
// Generate the sql statement by giving the columns, table, and current task list wanted
|
||||
if ( ( out_stmt = gen_sql_stmt(db, colnames, table, status) ) == NULL ){
|
||||
return 1;
|
||||
}
|
||||
// while there is still rows available
|
||||
while ( rc = sqlite3_step(out_stmt) == SQLITE_ROW ){
|
||||
// for each column print the column
|
||||
num_cols = sqlite3_column_count(out_stmt);
|
||||
for (i = 0; i < num_cols; i++){
|
||||
col_val = sqlite3_column_text(out_stmt, i);
|
||||
print_fixed_width(col_val);
|
||||
}
|
||||
// move down one and over to the start of the current task column
|
||||
printf("\n");
|
||||
X_goright(start_col);
|
||||
}
|
||||
|
||||
// if while loop broke and rc returned an error
|
||||
if ( rc == SQLITE_ERROR ){
|
||||
X_godown(max_rows);
|
||||
checksqlerr(rc, "step broken in display_task_list");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Once the task list is completely printed
|
||||
// reset to the top of the task lists
|
||||
X_goup(num_rows);
|
||||
|
||||
// if it is the last task list move down one past the longest list
|
||||
if ( status == "blocked"){
|
||||
X_godown(max_rows);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Print kanban table
|
||||
// All lists with task name and due date
|
||||
int view(sqlite3 *db, char *errmsg){
|
||||
int rc = 0;
|
||||
sqlite3_stmt* out_stmt;
|
||||
int numrows = 0;
|
||||
int* currcol = malloc(sizeof(int));
|
||||
|
||||
// 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 = "*";
|
||||
char *sql_query = "SELECT title,due_date ? tasks WHERE status='?'";
|
||||
char* colnames = "title,creation_date";
|
||||
|
||||
// Print Heading
|
||||
view_heading();
|
||||
|
||||
|
||||
// Print "today" tasks
|
||||
print_select_test(db, out_stmt, colnames, table, status);
|
||||
while ( rc = sqlite3_step(out_stmt) == SQLITE_ROW ){
|
||||
return sqlite3_column_int(out_stmt, 0);
|
||||
if ( display_task_list(TODAY_COL_START, db, colnames, table, status) ){
|
||||
return 1;
|
||||
}
|
||||
//*currcol = -1;
|
||||
//numrows = get_num_rows(db, table, status, errmsg);
|
||||
//rc = sqlite3_exec(db, sql_query, print_select, (void *)currcol, &errmsg);
|
||||
//checksqlerr(rc, errmsg);
|
||||
//X_goup(numrows);
|
||||
|
||||
//// Print "backlog" tasks
|
||||
//*currcol = 25;
|
||||
//status = "backlog";
|
||||
//sql_query = "SELECT title,due_date FROM tasks WHERE status='backlog'";
|
||||
//numrows = get_num_rows(db, table, status, errmsg);
|
||||
//rc = sqlite3_exec(db, sql_query, print_select, (void *)currcol, &errmsg);
|
||||
//checksqlerr(rc, errmsg);
|
||||
//X_goup(numrows);
|
||||
//X_goright(50);
|
||||
// Print "backlog" tasks
|
||||
status = "backlog";
|
||||
if ( display_task_list(BACKLOG_COL_START, db, colnames, table, status) ){
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Print "blocked" tasks
|
||||
//status = "blocked";
|
||||
//sql_query = "SELECT title,due_date FROM tasks WHERE status='blocked'";
|
||||
//numrows = get_num_rows(db, table, status, errmsg);
|
||||
//rc = sqlite3_exec(db, sql_query, print_select, 0, &errmsg);
|
||||
//checksqlerr(rc, errmsg);
|
||||
//X_godown(2);
|
||||
|
||||
//printf("%d\n", numrows);
|
||||
|
||||
|
||||
//get_num_rows(db, errmsg);
|
||||
status = "blocked";
|
||||
if ( display_task_list(BLOCKED_COL_START, db, colnames, table, status) ){
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main( int argc, char **argv ){
|
||||
sqlite3 *db;
|
||||
int rc = 0;
|
||||
char *errmsg;
|
||||
char* home_dir = getenv("HOME");
|
||||
char* filename = x_strconcat(home_dir, DB_PATH);
|
||||
|
||||
puts(filename);
|
||||
|
||||
puts(filename);
|
||||
|
||||
rc = opendb(&db, filename);
|
||||
rc = view(db, errmsg);
|
||||
rc = view(db);
|
||||
|
||||
puts("");
|
||||
puts("");
|
||||
puts("");
|
||||
puts("");
|
||||
rc = view_all(db, errmsg);
|
||||
rc = view_all(db);
|
||||
sqlite3_close(db);
|
||||
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
#define X_CYN "\x1B[36m"
|
||||
#define X_goup(y) printf("\x1B[%dF", y)
|
||||
#define X_godown(y) printf("\x1B[%dE", y)
|
||||
#define X_goupnocr(y) printf("\x1B[%dA", y)
|
||||
#define X_godownnocr(y) printf("\x1B[%dB", y)
|
||||
#define X_goright(x) printf("\x1B[%dC", x)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user