diff options
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); |