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 "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) {
<TH class='columnname'>Held By</TH>\
</TR>";
break;
case 'm':
case QMLEADERBOARD:
labels = "<TABLE class='center'>\
<TH class='tablename' COLSPAN='3'><H3><BR>Leaderboard</H3></TH>\
<TR>\
@ -46,7 +49,7 @@ static inline void print_tblheader(const char *c) {
<TH class='columnname'>Time</TH>\
</TR>";
break;
case 'p':
case QRPLAYER:
labels = "<TABLE class='center'>\
<TH class='tablename' COLSPAN='3'> <H3><BR>Ranks</H3> </TH>\
<TR>\
@ -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("<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);
} else {
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'.
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) {