Fixed bug where a junk query disables formatting for fields.

This commit is contained in:
2017-03-19 18:08:02 -07:00
parent ea45b27a6a
commit a01a1fe563

View File

@ -5,19 +5,22 @@
#include <sqlite3.h> #include <sqlite3.h>
#include "colors.h" #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"; char *qout = "queries/mranks.sql";
if (c != NULL) { if (c != NULL) {
switch(*c) { switch(*c) {
case 'm': case QMLEADERBOARD:
qout = "queries/mleaderboard-ojoin.sql"; qout = "queries/mleaderboard-ojoin.sql";
break; break;
case 'p': case QRPLAYER:
qout = "queries/rplayers.sql"; qout = "queries/rplayers.sql";
break; break;
case 't': default:
qout = "queries/test.txt"; *c = QOVERVIEW;
break; break;
} }
} }
@ -37,7 +40,7 @@ static inline void print_tblheader(const char *c) {
<TH class='columnname'>Held By</TH>\ <TH class='columnname'>Held By</TH>\
</TR>"; </TR>";
break; break;
case 'm': case QMLEADERBOARD:
labels = "<TABLE class='center'>\ labels = "<TABLE class='center'>\
<TH class='tablename' COLSPAN='3'><H3><BR>Leaderboard</H3></TH>\ <TH class='tablename' COLSPAN='3'><H3><BR>Leaderboard</H3></TH>\
<TR>\ <TR>\
@ -46,7 +49,7 @@ static inline void print_tblheader(const char *c) {
<TH class='columnname'>Time</TH>\ <TH class='columnname'>Time</TH>\
</TR>"; </TR>";
break; break;
case 'p': case QRPLAYER:
labels = "<TABLE class='center'>\ labels = "<TABLE class='center'>\
<TH class='tablename' COLSPAN='3'> <H3><BR>Ranks</H3> </TH>\ <TH class='tablename' COLSPAN='3'> <H3><BR>Ranks</H3> </TH>\
<TR>\ <TR>\
@ -79,11 +82,11 @@ static void print_time(const unsigned char *strcs) {
// display and format the results of the query. // display and format the results of the query.
static void qresult(sqlite3_stmt * const sp, const char *c) { static void qresult(sqlite3_stmt * const sp, const char *c) {
#define ISPLAYERNAME(x, y) (*x == 'm' && y == 1) || \ #define ISPLAYERNAME(x, y) (y == 1 && *x == QMLEADERBOARD) || \
(*x == '\0' && y == 3)|| \ (y == 3 && *x == QOVERVIEW)|| \
(*x == 'p' && y == 0) (y == 0 && *x == QRPLAYER)
#define ISMAPNAME(x, y) (*x == '\0' && y == 0) ||\ #define ISMAPNAME(x, y) (y == 0 && *x == QOVERVIEW) ||\
(*x == 'p' && y == 1) (y == 1 && *x == QRPLAYER)
int e; int e;
unsigned int i; unsigned int i;
const unsigned int cc = sqlite3_column_count(sp); 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); print_plname(field);
} else if (ISMAPNAME(c, i)) { } else if (ISMAPNAME(c, i)) {
printf("<TD><a href='/cgi/cts?map=%s'>%s</a></TD>", field, field); printf("<TD><a href='/cgi/cts?map=%s'>%s</a></TD>", field, field);
} else if (i == 2 && (*c == 'm' || *c == '\0')) { } else if (i == 2 && (*c == QMLEADERBOARD || *c == QOVERVIEW)) {
print_time(field); print_time(field);
} else { } else {
printf("<TD>%s</TD>", field); printf("<TD>%s</TD>", 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'. // the contents of mranks.sql is in const char 'sql'.
static bool executequery(const char *sql, const char *str) { static bool executequery(const char *sql, const char *str) {
const char *p = (str != NULL) ? strchr(str, '=') + 1 : NULL; 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; sqlite3 *db;
int con = sqlite3_open("db/cts.db", &db); int con = sqlite3_open("db/cts.db", &db);
if (con != SQLITE_OK) { 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.. // both allocates and frees memory used up by the string..
// containing the data from query files. // containing the data from query files.
void getquery(const char *qs) { void getquery(char * const qs) {
char *qf = NULL; char *qf = NULL;
char *fname = get_filename(qs); char *fname = get_filename(qs);
if (fname != NULL) { if (fname != NULL) {