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 = "
\
+ Map List | \
+ \
+ Name | \
+ Records | \
+ Best Time | \
+ Held By | \
+
";
+ break;
+ case 'm':
+ out = "\
+ Leaderboard
| \
+ \
+ Rank | \
+ Name | \
+ Time | \
+
";
+ break;
+ case 'p':
+ out = "\
+ Ranks | \
+ \
+ Name | \
+ Map | \
+ Rank | \
+
";
+ 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.\
\