summary refs log tree commit diff
path: root/database.h
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2019-12-23 21:08:32 -0500
committerJune McEnroe <june@causal.agency>2019-12-23 21:08:32 -0500
commitde5f00d71614a5018a6468d5fd7e3cc039c41ec6 (patch)
tree4d4bf449f922b8e1e6031afca650adf91a03744b /database.h
parentHandle NICK (diff)
downloadlitterbox-de5f00d71614a5018a6468d5fd7e3cc039c41ec6.tar.gz
litterbox-de5f00d71614a5018a6468d5fd7e3cc039c41ec6.zip
Factour out verbose, dbStep+reset
Diffstat (limited to 'database.h')
-rw-r--r--database.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/database.h b/database.h
index 6efe9d0..1dcc71b 100644
--- a/database.h
+++ b/database.h
@@ -44,6 +44,8 @@ enum Type {
 	Topic,
 };
 
+static bool verbose;
+
 static inline void dbExec(sqlite3 *db, const char *sql) {
 	int error = sqlite3_exec(db, sql, NULL, NULL, NULL);
 	if (error) errx(EX_SOFTWARE, "%s: %s", sqlite3_errmsg(db), sql);
@@ -173,6 +175,16 @@ static inline int dbStep(sqlite3_stmt *stmt) {
 	);
 }
 
+static inline void dbRun(sqlite3_stmt *stmt) {
+	dbStep(stmt);
+	if (verbose && sqlite3_changes(sqlite3_db_handle(stmt))) {
+		char *sql = sqlite3_expanded_sql(stmt);
+		if (sql) fprintf(stderr, "%s\n", sql);
+		sqlite3_free(sql);
+	}
+	sqlite3_reset(stmt);
+}
+
 static inline int dbVersion(sqlite3 *db) {
 	sqlite3_stmt *stmt = dbPrepare(db, false, SQL(PRAGMA user_version;));
 	dbStep(stmt);