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;
}
inline char *get_tblheader(const char c) {
inline void print_tblheader(const char *c) {
char *out;
switch (c) {
switch (*c) {
default:
out = "<TABLE class='center'>\
<TH class='tablename' COLSPAN='4'> <H3><BR>Map List</H3> </TH>\
@ -55,23 +55,28 @@ inline char *get_tblheader(const char c) {
</TR>";
break;
}
return out;
printf("%s", out);
}
//display and format the results of the query.
void qresult(sqlite3_stmt *sp) {
void qresult(sqlite3_stmt *sp, const char *c) {
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) {
cc = sqlite3_column_count(sp);
printf("<TR>");
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;
char *error;
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.
con = sqlite3_bind_text(s, 1, p, -1, NULL);
qresult(s);
qresult(s, &qc);
sqlite3_finalize(s);
sqlite3_close(db);
return true;
@ -114,7 +119,7 @@ void getquery(const char *qs) {
fclose(f);
}
qp = strchr(qs, '=') + 1;
executequery(qf, qp);
executequery(qf, qs);
free(qf);
}
@ -129,12 +134,13 @@ void html(void) {
In-game database is not directly synced with this web server.\
</p>\
</body></html>";
printf("%s", html_top);
// getquery(getenv("QUERY_STRING"));
printf("%s %s", html_top, html_bot);
getquery("map=pornstar-kaine");
printf("%s", html_bot);
}
int main(void) {
getquery("map=pornstar-kaine");
getquery("player=duHTyaSGpdTk7oebwPFoo899xPoTwP9bja4DUjCjTLo=");
html();
// getquery("player=duHTyaSGpdTk7oebwPFoo899xPoTwP9bja4DUjCjTLo=");
}