From a01a1fe5638077c33e48db3ab5f85c42cd4ec4f7 Mon Sep 17 00:00:00 2001 From: <> Date: Sun, 19 Mar 2017 18:08:02 -0700 Subject: [PATCH] Fixed bug where a junk query disables formatting for fields. --- includes/dbquery.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/includes/dbquery.c b/includes/dbquery.c index 59e1c6e..e541e0e 100644 --- a/includes/dbquery.c +++ b/includes/dbquery.c @@ -5,19 +5,22 @@ #include #include "colors.h" +#define QOVERVIEW 'o' +#define QRPLAYER 'p' +#define QMLEADERBOARD 'm' -static inline char *get_filename(const char *c) { +static inline char *get_filename(char * const c) { char *qout = "queries/mranks.sql"; if (c != NULL) { switch(*c) { - case 'm': + case QMLEADERBOARD: qout = "queries/mleaderboard-ojoin.sql"; break; - case 'p': + case QRPLAYER: qout = "queries/rplayers.sql"; break; - case 't': - qout = "queries/test.txt"; + default: + *c = QOVERVIEW; break; } } @@ -37,7 +40,7 @@ static inline void print_tblheader(const char *c) { Held By\ "; break; - case 'm': + case QMLEADERBOARD: labels = "\ \ \ @@ -46,7 +49,7 @@ static inline void print_tblheader(const char *c) { \ "; break; - case 'p': + case QRPLAYER: labels = "


Leaderboard

Time
\ \ \ @@ -79,11 +82,11 @@ static void print_time(const unsigned char *strcs) { // display and format the results of the query. static void qresult(sqlite3_stmt * const sp, const char *c) { -#define ISPLAYERNAME(x, y) (*x == 'm' && y == 1) || \ - (*x == '\0' && y == 3)|| \ - (*x == 'p' && y == 0) -#define ISMAPNAME(x, y) (*x == '\0' && y == 0) ||\ - (*x == 'p' && y == 1) +#define ISPLAYERNAME(x, y) (y == 1 && *x == QMLEADERBOARD) || \ + (y == 3 && *x == QOVERVIEW)|| \ + (y == 0 && *x == QRPLAYER) +#define ISMAPNAME(x, y) (y == 0 && *x == QOVERVIEW) ||\ + (y == 1 && *x == QRPLAYER) int e; unsigned int i; const unsigned int cc = sqlite3_column_count(sp); @@ -96,7 +99,7 @@ static void qresult(sqlite3_stmt * const sp, const char *c) { print_plname(field); } else if (ISMAPNAME(c, i)) { printf("", field, field); - } else if (i == 2 && (*c == 'm' || *c == '\0')) { + } else if (i == 2 && (*c == QMLEADERBOARD || *c == QOVERVIEW)) { print_time(field); } else { printf("", field); @@ -112,7 +115,7 @@ static void qresult(sqlite3_stmt * const sp, const char *c) { // the contents of mranks.sql is in const char 'sql'. static bool executequery(const char *sql, const char *str) { const char *p = (str != NULL) ? strchr(str, '=') + 1 : NULL; - const char qc = (str != NULL) ? str[0] : '\0'; + const char qc = (str != NULL) ? str[0] : QOVERVIEW; sqlite3 *db; int con = sqlite3_open("db/cts.db", &db); if (con != SQLITE_OK) { @@ -136,7 +139,7 @@ static bool executequery(const char *sql, const char *str) { // both allocates and frees memory used up by the string.. // containing the data from query files. -void getquery(const char *qs) { +void getquery(char * const qs) { char *qf = NULL; char *fname = get_filename(qs); if (fname != NULL) {


Ranks

%s%s