Added to view function
This commit is contained in:
parent
1e1163b96a
commit
bcf1c17bf7
85
src/dodo.c
85
src/dodo.c
@ -4,6 +4,8 @@
|
|||||||
#include "x_string.h"
|
#include "x_string.h"
|
||||||
#include "x_curses.h"
|
#include "x_curses.h"
|
||||||
|
|
||||||
|
#define SQLQUERY_MAX 100
|
||||||
|
|
||||||
int checksqlerr(int rc, char *errmsg){
|
int checksqlerr(int rc, char *errmsg){
|
||||||
if( rc!=SQLITE_OK ){
|
if( rc!=SQLITE_OK ){
|
||||||
fprintf(stderr, "SQL error: %s\n", errmsg);
|
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
|
// Print Heading TODO: obvi make this better
|
||||||
void view_heading(){
|
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");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
sqlite3_stmt *print_select_test(sqlite3 *db, char* colnames, char* table, char* status){
|
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;
|
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);
|
||||||
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;
|
return out_stmt;
|
||||||
}
|
}
|
||||||
@ -103,18 +103,14 @@ int get_num_rows(sqlite3 *db, char* table, char* status, char *errmsg){
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO error checking needs done
|
// TODO error checking needs done
|
||||||
//int print_status_column(sqlite3 *db, char* table, char* status){
|
int print_fixed_width(const unsigned char* str){
|
||||||
// int rc = 0;
|
if (str){
|
||||||
// sqlite3_stmt *out_stmt;
|
printf("%-19.19s", str);
|
||||||
// char *sql_query = "SELECT title,due_date ? tasks WHERE status='?'";
|
}else{
|
||||||
//
|
printf("%-19.19s","");
|
||||||
// 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
|
// Print kanban table
|
||||||
// All lists with task name and due date
|
// 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
|
// TODO just gotta use snprintf because can't bind column or table names
|
||||||
int view(sqlite3 *db, char *errmsg){
|
int view(sqlite3 *db, char *errmsg){
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
int i = 0;
|
||||||
|
int num_cols = 0;
|
||||||
|
const unsigned char* col_val;
|
||||||
sqlite3_stmt* out_stmt;
|
sqlite3_stmt* out_stmt;
|
||||||
int numrows = 0;
|
|
||||||
|
int numrows = -1;
|
||||||
int* currcol = malloc(sizeof(int));
|
int* currcol = malloc(sizeof(int));
|
||||||
|
//char sql_query[SQLQUERY_MAX];
|
||||||
char* table = "tasks";
|
char* table = "tasks";
|
||||||
char* status = "today";
|
char* status = "today";
|
||||||
char* colnames = "*";
|
char* colnames = "title,due_date";
|
||||||
char *sql_query = "SELECT title,due_date ? tasks WHERE status='?'";
|
//char *sql_query = "SELECT title,due_date ? tasks WHERE status='?'";
|
||||||
|
|
||||||
// Print Heading
|
// Print Heading
|
||||||
view_heading();
|
view_heading();
|
||||||
|
|
||||||
|
|
||||||
// Print "today" tasks
|
// 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);
|
out_stmt = print_select_test(db, colnames, table, status);
|
||||||
while ( rc = sqlite3_step(out_stmt) == SQLITE_ROW ){
|
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;
|
//*currcol = -1;
|
||||||
//numrows = get_num_rows(db, table, status, errmsg);
|
//numrows = get_num_rows(db, table, status, errmsg);
|
||||||
|
@ -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_goupnocr(y) printf("\x1B[%dA", y)
|
||||||
#define X_godownnocr(y) printf("\x1B[%dB", 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)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user