about summary refs log tree commit diff
path: root/server.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--server.c17
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()) {