diff --git a/src/dodo.c b/src/dodo.c index d3f43d9..fe5a6d1 100644 --- a/src/dodo.c +++ b/src/dodo.c @@ -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; } @@ -67,43 +67,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 @@ -136,8 +129,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 ){ @@ -156,7 +149,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 @@ -184,19 +177,19 @@ int view(sqlite3 *db){ // 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;