diff options
Diffstat (limited to '')
-rw-r--r-- | server.h | 40 |
1 files changed, 12 insertions, 28 deletions
diff --git a/server.h b/server.h index 4a18ef0..fd80278 100644 --- a/server.h +++ b/server.h @@ -99,14 +99,19 @@ enum kcgi_err searchPage(struct kreq *req); extern sqlite3 *db; +#define ENUM_STMTS \ + X(networks, NetworksQuery) \ + X(contexts, ContextsQuery) \ + X(motd, ContextsMOTDQuery) \ + X(topic, EventsTopicQuery) \ + X(eventsAfter, EventsAfterQuery) \ + X(eventsBefore, EventsBeforeQuery) \ + X(search, SearchQuery) + extern struct Statements { - sqlite3_stmt *networks; - sqlite3_stmt *contexts; - sqlite3_stmt *contextsMOTD; - sqlite3_stmt *eventsTopic; - sqlite3_stmt *eventsAfter; - sqlite3_stmt *eventsBefore; - sqlite3_stmt *search; +#define X(name, query) sqlite3_stmt *name; + ENUM_STMTS +#undef X } stmt; static inline void dbPrepare(sqlite3_stmt **stmt, const char *query) { @@ -116,27 +121,6 @@ static inline void dbPrepare(sqlite3_stmt **stmt, const char *query) { if (error) errx(EX_SOFTWARE, "%s: %s", sqlite3_errmsg(db), query); } -static inline void dbPrepareAll(void) { - dbPrepare(&stmt.networks, NetworksQuery); - dbPrepare(&stmt.contexts, ContextsQuery); - dbPrepare(&stmt.contextsMOTD, ContextsMOTDQuery); - dbPrepare(&stmt.eventsTopic, EventsTopicQuery); - dbPrepare(&stmt.eventsAfter, EventsAfterQuery); - dbPrepare(&stmt.eventsBefore, EventsBeforeQuery); - dbPrepare(&stmt.search, SearchQuery); -} - -static inline void dbClose(void) { - sqlite3_finalize(stmt.networks); - sqlite3_finalize(stmt.contexts); - sqlite3_finalize(stmt.contextsMOTD); - sqlite3_finalize(stmt.eventsTopic); - sqlite3_finalize(stmt.eventsAfter); - sqlite3_finalize(stmt.eventsBefore); - sqlite3_finalize(stmt.search); - sqlite3_close(db); -} - static inline int dbParam(sqlite3_stmt *stmt, const char *param) { int index = sqlite3_bind_parameter_index(stmt, param); if (index) return index; |