diff options
author | June McEnroe <june@causal.agency> | 2020-07-12 14:12:53 -0400 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2020-07-12 14:12:53 -0400 |
commit | 858d2cd9be35a5f6c051b37bfb2a02e920a888b4 (patch) | |
tree | 001cc4d79cd13a1f73fd79c9744719303d8b0662 /server.c | |
parent | Always show later messages link when using before query (diff) | |
download | scooper-858d2cd9be35a5f6c051b37bfb2a02e920a888b4.tar.gz scooper-858d2cd9be35a5f6c051b37bfb2a02e920a888b4.zip |
Use X macro for statements
Diffstat (limited to 'server.c')
-rw-r--r-- | server.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/server.c b/server.c index fad9a90..bc05299 100644 --- a/server.c +++ b/server.c @@ -26,6 +26,19 @@ sqlite3 *db; struct Statements stmt; +static void prepareAll(void) { +#define X(name, query) dbPrepare(&stmt.name, query); + ENUM_STMTS +#undef X +} + +static void finalizeAll(void) { +#define X(name, query) sqlite3_finalize(stmt.name); + ENUM_STMTS +#undef X + sqlite3_close(db); +} + const char *Pages[PagesLen] = { #define X(page, path) [page] = path, ENUM_PAGES @@ -84,7 +97,7 @@ int main(int argc, char *argv[]) { int error = sqlite3_open_v2(argv[optind], &db, SQLITE_OPEN_READONLY, NULL); if (error) errx(EX_NOINPUT, "%s: %s", argv[optind], sqlite3_errmsg(db)); - atexit(dbClose); + atexit(finalizeAll); sqlite3_stmt *check; error = sqlite3_prepare_v2( @@ -101,7 +114,7 @@ int main(int argc, char *argv[]) { } sqlite3_finalize(check); - dbPrepareAll(); + prepareAll(); if (test) return EX_OK; if (khttp_fcgi_test()) { |