From 3f04c1ad99e2dcd7348077b52b598d026a0d835d Mon Sep 17 00:00:00 2001 From: <> Date: Sun, 12 Mar 2017 19:32:57 -0700 Subject: [PATCH] added function for html table labels --- main.c | 72 +++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 56 insertions(+), 16 deletions(-) diff --git a/main.c b/main.c index 912c664..d49820d 100644 --- a/main.c +++ b/main.c @@ -23,9 +23,57 @@ inline char *get_filename(const char c) { return qout; } +inline char *get_tblheader(const char c) { + char *out; + switch (c) { + default: + out = "\ + \ + \ + \ + \ + \ + \ + "; + break; + case 'm': + out = "


Map List

NameRecordsBest TimeHeld By
\ + \ + \ + \ + \ + \ + "; + break; + case 'p': + out = "


Leaderboard

RankNameTime
\ + \ + \ + \ + \ + \ + "; + break; + } + return out; +} + +//display and format the results of the query. +void qresult(sqlite3_stmt *sp) { + int e; + unsigned int cc, i; + while ((e = sqlite3_step(sp)) == SQLITE_ROW) { + cc = sqlite3_column_count(sp); + for (i = 0; i < cc; i++) { + printf("%s", sqlite3_column_text(sp, i)); + } + printf("\n"); + } +} + bool executequery(const char *sql, const char *p) { - sqlite3 *db; - char *error; + sqlite3 *db; + char *error; int con = sqlite3_open("db/cts.db", &db); if (con != SQLITE_OK) { fprintf(stderr, "Can not open database: %s\n", sqlite3_errmsg(db)); @@ -40,15 +88,7 @@ bool executequery(const char *sql, const char *p) { } // bind parameter with a string length that is the # of bytes to null char. con = sqlite3_bind_text(s, 1, p, -1, NULL); - int e; - unsigned int cc, i; - while ((e = sqlite3_step(s)) == SQLITE_ROW) { - cc = sqlite3_column_count(s); - for (i = 0; i < cc; i++) { - printf("%s, ", sqlite3_column_text(s, i)); - } - printf("\n"); - } + qresult(s); sqlite3_finalize(s); sqlite3_close(db); return true; @@ -71,9 +111,9 @@ void getquery(const char *qs) { fread(qf, sizeof(char), size, f); } } + fclose(f); } - qp = strchr(qs, '=') + 1; // increment to exclude '=' - printf("%x: \n\n%s\n", qf, qf); + qp = strchr(qs, '=') + 1; executequery(qf, qp); free(qf); } @@ -89,9 +129,9 @@ void html(void) { In-game database is not directly synced with this web server.\

\ "; - getquery(getenv("QUERY_STRING")); - printf("%s %s", html_top, html_bot); - return; + // getquery(getenv("QUERY_STRING")); + + printf("%s %s", html_top, html_bot); } int main(void) {


Ranks

NameMapRank