diff options
author | June McEnroe <june@causal.agency> | 2019-12-23 21:08:32 -0500 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2019-12-23 21:08:32 -0500 |
commit | de5f00d71614a5018a6468d5fd7e3cc039c41ec6 (patch) | |
tree | 4d4bf449f922b8e1e6031afca650adf91a03744b /database.h | |
parent | Handle NICK (diff) | |
download | litterbox-de5f00d71614a5018a6468d5fd7e3cc039c41ec6.tar.gz litterbox-de5f00d71614a5018a6468d5fd7e3cc039c41ec6.zip |
Factour out verbose, dbStep+reset
Diffstat (limited to 'database.h')
-rw-r--r-- | database.h | 12 |
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); |