Added display_status_list func
This commit is contained in:
parent
bcf1c17bf7
commit
daabdcbfac
133
src/dodo.c
133
src/dodo.c
@ -41,8 +41,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);
|
||||
@ -78,22 +79,23 @@ sqlite3_stmt *print_select_test(sqlite3 *db, char* colnames, char* table, char*
|
||||
|
||||
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);
|
||||
checksqlerr(rc, "prepare broken");
|
||||
|
||||
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;
|
||||
|
||||
rc = sqlite3_prepare_v2(db, sql_query, -1, &out_stmt, NULL);
|
||||
checksqlerr(rc, errmsg);
|
||||
checksqlerr(rc, "prepare broken");
|
||||
|
||||
rc = sqlite3_bind_text(out_stmt, 1, status, -1, SQLITE_STATIC);
|
||||
checksqlerr(rc, errmsg);
|
||||
checksqlerr(rc, "bind broken");
|
||||
|
||||
while ( rc = sqlite3_step(out_stmt) == SQLITE_ROW ){
|
||||
return sqlite3_column_int(out_stmt, 0);
|
||||
@ -102,131 +104,82 @@ int get_num_rows(sqlite3 *db, char* table, char* status, char *errmsg){
|
||||
return 1;
|
||||
}
|
||||
|
||||
// TODO error checking needs done
|
||||
// Print columns
|
||||
int print_fixed_width(const unsigned char* str){
|
||||
if (str){
|
||||
printf("%-19.19s", str);
|
||||
}else{
|
||||
printf("%-19.19s","");
|
||||
}
|
||||
}
|
||||
|
||||
void display_status_list(int start_col, sqlite3 *db, char* colnames, char* table, char* status){
|
||||
int rc = 0;
|
||||
int i = 0;
|
||||
int numrows = 0;
|
||||
int num_cols = 0;
|
||||
char* errmsg;
|
||||
const unsigned char* col_val;
|
||||
sqlite3_stmt* out_stmt;
|
||||
|
||||
X_goright(start_col);
|
||||
numrows = get_num_rows(db, table, status);
|
||||
out_stmt = print_select_test(db, colnames, table, status);
|
||||
while ( rc = sqlite3_step(out_stmt) == SQLITE_ROW ){
|
||||
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);
|
||||
}
|
||||
printf("\n");
|
||||
X_goright(start_col);
|
||||
}
|
||||
X_goup(numrows);
|
||||
}
|
||||
|
||||
// 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 *errmsg){
|
||||
int rc = 0;
|
||||
int i = 0;
|
||||
int num_cols = 0;
|
||||
const unsigned char* col_val;
|
||||
sqlite3_stmt* out_stmt;
|
||||
|
||||
int numrows = -1;
|
||||
int* currcol = malloc(sizeof(int));
|
||||
//char sql_query[SQLQUERY_MAX];
|
||||
int view(sqlite3 *db){
|
||||
char* table = "tasks";
|
||||
char* status = "today";
|
||||
char* colnames = "title,due_date";
|
||||
//char *sql_query = "SELECT title,due_date ? tasks WHERE status='?'";
|
||||
|
||||
char* colnames = "title,creation_date";
|
||||
|
||||
// Print Heading
|
||||
view_heading();
|
||||
|
||||
|
||||
// Print "today" tasks
|
||||
X_goup(numrows);
|
||||
X_goright(-1);
|
||||
numrows = get_num_rows(db, table, status, errmsg);
|
||||
out_stmt = print_select_test(db, colnames, table, status);
|
||||
while ( rc = sqlite3_step(out_stmt) == SQLITE_ROW ){
|
||||
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);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
X_goup(numrows);
|
||||
X_goright(33);
|
||||
display_status_list(-1, db, colnames, table, status);
|
||||
|
||||
// Print "backlog" tasks
|
||||
status = "backlog";
|
||||
numrows = get_num_rows(db, table, status, errmsg);
|
||||
out_stmt = print_select_test(db, colnames, table, status);
|
||||
while ( rc = sqlite3_step(out_stmt) == SQLITE_ROW ){
|
||||
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);
|
||||
}
|
||||
printf("\n");
|
||||
X_goright(33);
|
||||
}
|
||||
X_goup(numrows);
|
||||
X_goright(66);
|
||||
|
||||
status = "blocked";
|
||||
numrows = get_num_rows(db, table, status, errmsg);
|
||||
out_stmt = print_select_test(db, colnames, table, status);
|
||||
while ( rc = sqlite3_step(out_stmt) == SQLITE_ROW ){
|
||||
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);
|
||||
}
|
||||
printf("\n");
|
||||
X_goright(66);
|
||||
}
|
||||
//*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);
|
||||
display_status_list(33, db, colnames, table, status);
|
||||
|
||||
// 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";
|
||||
display_status_list(66, db, colnames, table, status);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user