Broke a bunch of things, TODO: make print_select function

This commit is contained in:
xavi 2024-08-25 20:46:52 -07:00
parent ffb26ebefc
commit 61e9ee7047
2 changed files with 91 additions and 57 deletions

View File

@ -38,25 +38,55 @@ int callback(void *NotUsed, int argc, char **argv, char **azColName){
return 0; return 0;
} }
int get_num_rows_sql_helper(void *NotUsed, int argc, char **argv, char **azColName){ // FOR DEBUG
int view_all(sqlite3 *db, char *errmsg){
int rc = 0;
if ( !argv[0] ){ //rc = sqlite3_exec(db, "SELECT * FROM all_info;", print_select, 0, &errmsg);
return 1; rc = sqlite3_exec(db, "SELECT * FROM tasks;", callback, 0, &errmsg);
//rc = sqlite3_exec(db, "SELECT * FROM entries;", print_select, 0, &errmsg);
checksqlerr(rc, errmsg);
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");
} }
printf("\n");
printf("%s\n", argv[0]);
return 0; 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);
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 = ?";
int rc = 0;
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);
return 0;
}
// Get number of tasks from tasks table give status // Get number of tasks from tasks table give status
// TODO: Gotta make the error checking not broken // TODO: Gotta make the error checking not broken
int get_num_rows(sqlite3 *db, char* status, char *errmsg){ int get_num_rows(sqlite3 *db, char* table, char* status, char *errmsg){
char *sql_query = "SELECT COUNT(*) FROM tasks WHERE status = ?"; char *sql_query = "SELECT COUNT(*) FROM tasks WHERE status = ?";
sqlite3_stmt *out_stmt; sqlite3_stmt *out_stmt;
int rc = 0; int rc = 0;
//rc = sqlite3_exec(db, sql_query, get_num_rows_sql_helper, 0, &errmsg);
//checksqlerr(rc, errmsg);
rc = sqlite3_prepare_v2(db, sql_query, -1, &out_stmt, NULL); rc = sqlite3_prepare_v2(db, sql_query, -1, &out_stmt, NULL);
checksqlerr(rc, errmsg); checksqlerr(rc, errmsg);
@ -71,63 +101,66 @@ int get_num_rows(sqlite3 *db, char* status, char *errmsg){
return 1; return 1;
} }
int print_select(void *NotUsed, int argc, char **argv, char **azColName){ // TODO error checking needs done
int i = 0; //int print_status_column(sqlite3 *db, char* table, char* status){
for(i=0; i<argc; i++){ // int rc = 0;
printf("%s ", argv[i] ? argv[i] : "NULL"); // sqlite3_stmt *out_stmt;
} // char *sql_query = "SELECT title,due_date ? tasks WHERE status='?'";
printf("\n"); //
// rc = sqlite3_prepare_v2(db, sql_query, -1, out_stmt, NULL);
return 0; //
} // rc = sqlite3_bind_text(out_stmt, 1, table, -1, SQLITE_STATIC);
// rc = sqlite3_bind_text(out_stmt, 2, status, -1, SQLITE_STATIC);
//
int view_all(sqlite3 *db, char *errmsg){ //
int rc = 0; //}
rc = sqlite3_exec(db, "SELECT * FROM all_info;", print_select, 0, &errmsg);
checksqlerr(rc, errmsg);
return rc;
}
// Print kanban table
// All lists with task name and due date
int view(sqlite3 *db, char *errmsg){ int view(sqlite3 *db, char *errmsg){
int rc = 0; int rc = 0;
sqlite3_stmt* out_stmt;
int numrows = 0; int numrows = 0;
int* currcol = malloc(sizeof(int));
char* table = "tasks";
char* status = "today"; char* status = "today";
char *sql_query = "SELECT title,due_date FROM tasks WHERE status='today'"; char* colnames = "*";
char *sql_query = "SELECT title,due_date ? tasks WHERE status='?'";
// Print Heading TODO: make func // Print Heading
printf("%s%stitle due date%s", X_BOLD, X_UNDL, X_RST); 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("\n");
// Print "today" tasks // Print "today" tasks
numrows = get_num_rows(db, status, errmsg); print_select_test(db, out_stmt, colnames, table, status);
rc = sqlite3_exec(db, sql_query, print_select, 0, &errmsg); while ( rc = sqlite3_step(out_stmt) == SQLITE_ROW ){
checksqlerr(rc, errmsg); return sqlite3_column_int(out_stmt, 0);
X_goup(numrows); }
X_goright(25); //*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 //// Print "backlog" tasks
status = "backlog"; //*currcol = 25;
sql_query = "SELECT title,due_date FROM tasks WHERE status='backlog'"; //status = "backlog";
numrows = get_num_rows(db, status, errmsg); //sql_query = "SELECT title,due_date FROM tasks WHERE status='backlog'";
rc = sqlite3_exec(db, sql_query, print_select, 0, &errmsg); //numrows = get_num_rows(db, table, status, errmsg);
checksqlerr(rc, errmsg); //rc = sqlite3_exec(db, sql_query, print_select, (void *)currcol, &errmsg);
X_goup(numrows); //checksqlerr(rc, errmsg);
X_goright(50); //X_goup(numrows);
//X_goright(50);
// Print "blocked" tasks // Print "blocked" tasks
status = "blocked"; //status = "blocked";
sql_query = "SELECT title,due_date FROM tasks WHERE status='blocked'"; //sql_query = "SELECT title,due_date FROM tasks WHERE status='blocked'";
numrows = get_num_rows(db, status, errmsg); //numrows = get_num_rows(db, table, status, errmsg);
rc = sqlite3_exec(db, sql_query, print_select, 0, &errmsg); //rc = sqlite3_exec(db, sql_query, print_select, 0, &errmsg);
checksqlerr(rc, errmsg); //checksqlerr(rc, errmsg);
X_godown(20); //X_godown(2);
printf("%d\n", numrows); //printf("%d\n", numrows);
//get_num_rows(db, errmsg); //get_num_rows(db, errmsg);
@ -147,11 +180,11 @@ int main( int argc, char **argv ){
rc = opendb(&db, filename); rc = opendb(&db, filename);
rc = view(db, errmsg); rc = view(db, errmsg);
// puts(""); puts("");
// puts(""); puts("");
// puts(""); puts("");
// puts(""); puts("");
// rc = view_all(db, errmsg); rc = view_all(db, errmsg);
sqlite3_close(db); sqlite3_close(db);

View File

@ -7,6 +7,7 @@
#define X_CYN "\x1B[36m" #define X_CYN "\x1B[36m"
#define X_goup(y) printf("\x1B[%dF", y) #define X_goup(y) printf("\x1B[%dF", y)
#define X_godown(y) printf("\x1B[%dE", y) #define X_godown(y) printf("\x1B[%dE", y)
#define X_godownnocr(y) printf("\x1B[%dB", y)
#define X_goright(x) printf("\x1B[%dC", x) #define X_goright(x) printf("\x1B[%dC", x)