added function for html table labels

This commit is contained in:
2017-03-12 19:32:57 -07:00
parent 51830a8122
commit 3f04c1ad99

72
main.c
View File

@ -23,9 +23,57 @@ inline char *get_filename(const char c) {
return qout; return qout;
} }
inline char *get_tblheader(const char c) {
char *out;
switch (c) {
default:
out = "<TABLE class='center'>\
<TH class='tablename' COLSPAN='4'> <H3><BR>Map List</H3> </TH>\
<TR>\
<TH class='columnname'>Name</TH>\
<TH class='columnname'>Records</TH>\
<TH class='columnname'>Best Time</TH>\
<TH class='columnname'>Held By</TH>\
</TR>";
break;
case 'm':
out = "<TABLE class='center'>\
<TH class='tablename' COLSPAN='3'><H3><BR>Leaderboard</H3></TH>\
<TR>\
<TH class='columnname'>Rank</TH>\
<TH class='columnname'>Name</TH>\
<TH class='columnname'>Time</TH>\
</TR>";
break;
case 'p':
out = "<TABLE class='center'>\
<TH class='tablename' COLSPAN='3'> <H3><BR>Ranks</H3> </TH>\
<TR>\
<TH class='columnname'>Name</TH>\
<TH class='columnname'>Map</TH>\
<TH class='columnname'>Rank</TH>\
</TR>";
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) { bool executequery(const char *sql, const char *p) {
sqlite3 *db; sqlite3 *db;
char *error; char *error;
int con = sqlite3_open("db/cts.db", &db); int con = sqlite3_open("db/cts.db", &db);
if (con != SQLITE_OK) { if (con != SQLITE_OK) {
fprintf(stderr, "Can not open database: %s\n", sqlite3_errmsg(db)); 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. // bind parameter with a string length that is the # of bytes to null char.
con = sqlite3_bind_text(s, 1, p, -1, NULL); con = sqlite3_bind_text(s, 1, p, -1, NULL);
int e; qresult(s);
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");
}
sqlite3_finalize(s); sqlite3_finalize(s);
sqlite3_close(db); sqlite3_close(db);
return true; return true;
@ -71,9 +111,9 @@ void getquery(const char *qs) {
fread(qf, sizeof(char), size, f); fread(qf, sizeof(char), size, f);
} }
} }
fclose(f);
} }
qp = strchr(qs, '=') + 1; // increment to exclude '=' qp = strchr(qs, '=') + 1;
printf("%x: \n\n%s\n", qf, qf);
executequery(qf, qp); executequery(qf, qp);
free(qf); free(qf);
} }
@ -89,9 +129,9 @@ void html(void) {
In-game database is not directly synced with this web server.\ In-game database is not directly synced with this web server.\
</p>\ </p>\
</body></html>"; </body></html>";
getquery(getenv("QUERY_STRING")); // getquery(getenv("QUERY_STRING"));
printf("%s %s", html_top, html_bot);
return; printf("%s %s", html_top, html_bot);
} }
int main(void) { int main(void) {