taken into account of a NULL query string
This commit is contained in:
parent
9894f3c77a
commit
0a9b9a2ef6
24
main.c
24
main.c
@ -4,12 +4,10 @@
|
||||
#include <string.h>
|
||||
#include <sqlite3.h>
|
||||
|
||||
inline char *get_filename(const char c) {
|
||||
char *qout;
|
||||
switch(c) {
|
||||
default:
|
||||
qout = "queries/mranks.sql";
|
||||
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;
|
||||
@ -20,6 +18,7 @@ inline char *get_filename(const char c) {
|
||||
qout = "queries/test.txt";
|
||||
break;
|
||||
}
|
||||
}
|
||||
return qout;
|
||||
}
|
||||
|
||||
@ -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) {
|
||||
// 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) {
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
qp = strchr(qs, '=') + 1;
|
||||
executequery(qf, qs);
|
||||
free(qf);
|
||||
}
|
||||
@ -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…
Reference in New Issue
Block a user