Added to view function

This commit is contained in:
xavi 2024-09-03 17:16:42 -07:00
parent 1e1163b96a
commit bcf1c17bf7
2 changed files with 63 additions and 23 deletions

View File

@ -4,6 +4,8 @@
#include "x_string.h"
#include "x_curses.h"
#define SQLQUERY_MAX 100
int checksqlerr(int rc, char *errmsg){
if( rc!=SQLITE_OK ){
fprintf(stderr, "SQL error: %s\n", errmsg);
@ -63,21 +65,19 @@ 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");
}
sqlite3_stmt *print_select_test(sqlite3 *db, char* colnames, char* table, char* status){
char *sql_query = "SELECT ? FROM ? WHERE 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);
return out_stmt;
}
@ -103,18 +103,14 @@ int get_num_rows(sqlite3 *db, char* table, char* status, char *errmsg){
}
// 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);
//
//
//}
int print_fixed_width(const unsigned char* str){
if (str){
printf("%-19.19s", str);
}else{
printf("%-19.19s","");
}
}
// Print kanban table
// All lists with task name and due date
@ -122,22 +118,65 @@ int get_num_rows(sqlite3 *db, char* table, char* status, char *errmsg){
// 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 = 0;
int numrows = -1;
int* currcol = malloc(sizeof(int));
//char sql_query[SQLQUERY_MAX];
char* table = "tasks";
char* status = "today";
char* colnames = "*";
char *sql_query = "SELECT title,due_date ? tasks WHERE status='?'";
char* colnames = "title,due_date";
//char *sql_query = "SELECT title,due_date ? tasks WHERE status='?'";
// 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 ){
printf("%d\n", sqlite3_column_int(out_stmt, 0));
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);
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);

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