+#include "filesys.h"
+#include "exceptions.h"
+#include "settings.h"
+#include "util/string.h"
+
+#include <cassert>
+
+
+#define SQLRES(s, r) \
+ if ((s) != (r)) { \
+ throw FileNotGoodException(std::string(\
+ "SQLite3 database error (" \
+ __FILE__ ":" TOSTRING(__LINE__) \
+ "): ") +\
+ sqlite3_errmsg(m_database)); \
+ }
+#define SQLOK(s) SQLRES(s, SQLITE_OK)
+
+#define PREPARE_STATEMENT(name, query) \
+ SQLOK(sqlite3_prepare_v2(m_database, query, -1, &m_stmt_##name, NULL))
+
+#define FINALIZE_STATEMENT(statement) \
+ if (sqlite3_finalize(statement) != SQLITE_OK) { \
+ throw FileNotGoodException(std::string( \
+ "SQLite3: Failed to finalize " #statement ": ") + \
+ sqlite3_errmsg(m_database)); \
+ }