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;
}
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] ){
return 1;
//rc = sqlite3_exec(db, "SELECT * FROM all_info;", print_select, 0, &errmsg);
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;
}
// 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
// TODO: Gotta make the error checking not broken
int get_num_rows(sqlite3 *db, char* status, char *errmsg){
char *sql_query = "SELECT COUNT(*) FROM tasks WHERE status = ?";
int get_num_rows(sqlite3 *db, char* table, char* status, char *errmsg){
char *sql_query = "SELECT COUNT(*) FROM tasks WHERE status = ?";
sqlite3_stmt *out_stmt;
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);
checksqlerr(rc, errmsg);
@ -71,63 +101,66 @@ int get_num_rows(sqlite3 *db, char* status, char *errmsg){
return 1;
}
int print_select(void *NotUsed, int argc, char **argv, char **azColName){
int i = 0;
for(i=0; i<argc; i++){
printf("%s ", argv[i] ? argv[i] : "NULL");
}
printf("\n");
return 0;
}
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;
}
// 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 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));
char* table = "tasks";
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
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");
// Print Heading
view_heading();
// Print "today" tasks
numrows = get_num_rows(db, status, errmsg);
rc = sqlite3_exec(db, sql_query, print_select, 0, &errmsg);
checksqlerr(rc, errmsg);
X_goup(numrows);
X_goright(25);
print_select_test(db, out_stmt, colnames, table, status);
while ( rc = sqlite3_step(out_stmt) == SQLITE_ROW ){
return sqlite3_column_int(out_stmt, 0);
}
//*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
status = "backlog";
sql_query = "SELECT title,due_date FROM tasks WHERE status='backlog'";
numrows = get_num_rows(db, status, errmsg);
rc = sqlite3_exec(db, sql_query, print_select, 0, &errmsg);
checksqlerr(rc, errmsg);
X_goup(numrows);
X_goright(50);
//// 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 "blocked" tasks
status = "blocked";
sql_query = "SELECT title,due_date FROM tasks WHERE status='blocked'";
numrows = get_num_rows(db, status, errmsg);
rc = sqlite3_exec(db, sql_query, print_select, 0, &errmsg);
checksqlerr(rc, errmsg);
X_godown(20);
//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);
//printf("%d\n", numrows);
//get_num_rows(db, errmsg);
@ -147,11 +180,11 @@ int main( int argc, char **argv ){
rc = opendb(&db, filename);
rc = view(db, errmsg);
// puts("");
// puts("");
// puts("");
// puts("");
// rc = view_all(db, errmsg);
puts("");
puts("");
puts("");
puts("");
rc = view_all(db, errmsg);
sqlite3_close(db);

View File

@ -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_godownnocr(y) printf("\x1B[%dB", y)
#define X_goright(x) printf("\x1B[%dC", x)