got tables to display in a basic way

This commit is contained in:
2017-03-12 20:03:51 -07:00
parent 3f04c1ad99
commit 9894f3c77a

36
main.c
View File

@ -23,9 +23,9 @@ inline char *get_filename(const char c) {
return qout; return qout;
} }
inline char *get_tblheader(const char c) { inline void print_tblheader(const char *c) {
char *out; char *out;
switch (c) { switch (*c) {
default: default:
out = "<TABLE class='center'>\ out = "<TABLE class='center'>\
<TH class='tablename' COLSPAN='4'> <H3><BR>Map List</H3> </TH>\ <TH class='tablename' COLSPAN='4'> <H3><BR>Map List</H3> </TH>\
@ -55,23 +55,28 @@ inline char *get_tblheader(const char c) {
</TR>"; </TR>";
break; break;
} }
return out; printf("%s", out);
} }
//display and format the results of the query. //display and format the results of the query.
void qresult(sqlite3_stmt *sp) { void qresult(sqlite3_stmt *sp, const char *c) {
int e; int e;
unsigned int cc, i; unsigned int i;
unsigned int cc = sqlite3_column_count(sp);
print_tblheader(c);
while ((e = sqlite3_step(sp)) == SQLITE_ROW) { while ((e = sqlite3_step(sp)) == SQLITE_ROW) {
cc = sqlite3_column_count(sp); printf("<TR>");
for (i = 0; i < cc; i++) { for (i = 0; i < cc; i++) {
printf("%s", sqlite3_column_text(sp, i)); printf("<TD>%s</TD>", sqlite3_column_text(sp, i));
} }
printf("\n"); printf("</TR>");
} }
printf("</TABLE>");
} }
bool executequery(const char *sql, const char *p) { bool executequery(const char *sql, const char *str) {
const char *p = strchr(str, '=') + 1;
const char qc = str[0];
sqlite3 *db; sqlite3 *db;
char *error; char *error;
int con = sqlite3_open("db/cts.db", &db); int con = sqlite3_open("db/cts.db", &db);
@ -88,7 +93,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);
qresult(s); qresult(s, &qc);
sqlite3_finalize(s); sqlite3_finalize(s);
sqlite3_close(db); sqlite3_close(db);
return true; return true;
@ -114,7 +119,7 @@ void getquery(const char *qs) {
fclose(f); fclose(f);
} }
qp = strchr(qs, '=') + 1; qp = strchr(qs, '=') + 1;
executequery(qf, qp); executequery(qf, qs);
free(qf); free(qf);
} }
@ -129,12 +134,13 @@ 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>";
printf("%s", html_top);
// getquery(getenv("QUERY_STRING")); // getquery(getenv("QUERY_STRING"));
getquery("map=pornstar-kaine");
printf("%s %s", html_top, html_bot); printf("%s", html_bot);
} }
int main(void) { int main(void) {
getquery("map=pornstar-kaine"); html();
getquery("player=duHTyaSGpdTk7oebwPFoo899xPoTwP9bja4DUjCjTLo="); // getquery("player=duHTyaSGpdTk7oebwPFoo899xPoTwP9bja4DUjCjTLo=");
} }