Compare commits

..

3 Commits

View File

@ -14,7 +14,7 @@ int checksqlerr(int rc, char *errmsg){
if( rc!=SQLITE_OK ){
fprintf(stderr, "SQL error: %s\n", errmsg);
sqlite3_free(errmsg);
return 1;
return -1;
}
return 0;
}
@ -56,20 +56,14 @@ int view_all(sqlite3 *db){
return rc;
}
int print_select(void *passed_col, int argc, char **argv, char **azColName){
int *currcol = (int *)passed_col;
int i = 0;
X_goright(*currcol);
for(i=0; i<argc; i++){
printf("%s ", argv[i] ? argv[i] : "NULL");
}
// Print Heading TODO: obvi make this better
void display_heading(){
printf("\n");
printf("%s Today %s", X_BOLD, X_RST);
printf(" %s Backlog %s", X_BOLD, X_RST);
printf(" %s Blocked %s", X_BOLD, X_RST);
printf("\n");
return 0;
}
// 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);
@ -79,43 +73,36 @@ void view_heading(){
// 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){
int gen_sql_stmt(sqlite3 *db, sqlite3_stmt** out_stmt, char* colnames, char* table, char* status){
char sql_query[SQLQUERY_MAX];
int rc = 0;
sqlite3_stmt *out_stmt;
//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_prepare_v2(db, sql_query, -1, out_stmt, NULL);
if (checksqlerr(rc, "prepare broken in gen_sql_stmt")){
return NULL;
return -1;
}
return out_stmt;
return 0;
}
// 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 *sql_query = "SELECT COUNT(*) FROM tasks WHERE status = ?";
sqlite3_stmt *out_stmt;
int rc = 0;
char *col_name = "COUNT(*)";
if ( ( out_stmt = gen_sql_stmt(db, col_name, table, status) ) == NULL ){
return 1;
if ( gen_sql_stmt(db, &out_stmt, col_name, table, status) == 1 ){
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, "bind broken in get_num_rows");
while ( rc = sqlite3_step(out_stmt) == SQLITE_ROW ){
return sqlite3_column_int(out_stmt, 0);
}
return 1;
return -1;
}
// Print columns
@ -148,8 +135,8 @@ int display_task_list(int start_col, sqlite3 *db, char* colnames, char* table, c
}
// 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;
if ( gen_sql_stmt(db, &out_stmt, colnames, table, status) ){
return -1;
}
// while there is still rows available
while ( rc = sqlite3_step(out_stmt) == SQLITE_ROW ){
@ -168,7 +155,7 @@ int display_task_list(int start_col, sqlite3 *db, char* colnames, char* table, c
if ( rc == SQLITE_ERROR ){
X_godown(max_rows);
checksqlerr(rc, "step broken in display_task_list");
return 1;
return -1;
}
// Once the task list is completely printed
@ -192,23 +179,23 @@ int view(sqlite3 *db){
char* colnames = "title,creation_date";
// Print Heading
view_heading();
display_heading();
// Print "today" tasks
if ( display_task_list(TODAY_COL_START, db, colnames, table, status) ){
return 1;
return -1;
}
// Print "backlog" tasks
status = "backlog";
if ( display_task_list(BACKLOG_COL_START, db, colnames, table, status) ){
return 1;
return -1;
}
// Print "blocked" tasks
status = "blocked";
if ( display_task_list(BLOCKED_COL_START, db, colnames, table, status) ){
return 1;
return -1;
}
return 0;