Browse Source

taken into account of a NULL query string

master
5 years ago
parent
commit
0a9b9a2ef6
  1. 44
      main.c

44
main.c

@ -4,21 +4,20 @@ @@ -4,21 +4,20 @@
#include <string.h>
#include <sqlite3.h>
inline char *get_filename(const char c) {
char *qout;
switch(c) {
default:
qout = "queries/mranks.sql";
break;
case 'm':
qout = "queries/mleaderboard-ojoin.sql";
break;
case 'p':
qout = "queries/rplayers.sql";
break;
case 't':
qout = "queries/test.txt";
break;
inline char *get_filename(const char *c) {
char *qout = "queries/mranks.sql";
if (c != NULL) {
switch(*c) {
case 'm':
qout = "queries/mleaderboard-ojoin.sql";
break;
case 'p':
qout = "queries/rplayers.sql";
break;
case 't':
qout = "queries/test.txt";
break;
}
}
return qout;
}
@ -58,7 +57,7 @@ inline void print_tblheader(const char *c) { @@ -58,7 +57,7 @@ inline void print_tblheader(const char *c) {
printf("%s", out);
}
//display and format the results of the query.
// display and format the results of the query.
void qresult(sqlite3_stmt *sp, const char *c) {
int e;
unsigned int i;
@ -74,9 +73,12 @@ void qresult(sqlite3_stmt *sp, const char *c) { @@ -74,9 +73,12 @@ void qresult(sqlite3_stmt *sp, const char *c) {
printf("</TABLE>");
}
// const char 'sql' is never NULL.
// const char 'str' may be NULL, however it is only when
// the contents of mranks.sql is in const char 'sql'.
bool executequery(const char *sql, const char *str) {
const char *p = strchr(str, '=') + 1;
const char qc = str[0];
const char *p = (str != NULL) ? strchr(str, '=') + 1 : NULL;
const char qc = (str != NULL) ? str[0] : '\0';
sqlite3 *db;
char *error;
int con = sqlite3_open("db/cts.db", &db);
@ -103,7 +105,7 @@ bool executequery(const char *sql, const char *str) { @@ -103,7 +105,7 @@ bool executequery(const char *sql, const char *str) {
// containing the data from query files.
void getquery(const char *qs) {
char *qf, *qp;
char *fname = get_filename(qs[0]);
char *fname = get_filename(qs);
if (fname != NULL) {
FILE *f = fopen(fname, "r");
if (f != NULL && qf != NULL) {
@ -118,7 +120,6 @@ void getquery(const char *qs) { @@ -118,7 +120,6 @@ void getquery(const char *qs) {
}
fclose(f);
}
qp = strchr(qs, '=') + 1;
executequery(qf, qs);
free(qf);
}
@ -136,7 +137,8 @@ void html(void) { @@ -136,7 +137,8 @@ void html(void) {
</body></html>";
printf("%s", html_top);
// getquery(getenv("QUERY_STRING"));
getquery("map=pornstar-kaine");
// getquery("map=pornstar-kaine");
getquery(NULL);
printf("%s", html_bot);
}

Loading…
Cancel
Save