diff --git a/wallet/db.c b/wallet/db.c index 7036ae639..f5cb2a9e6 100644 --- a/wallet/db.c +++ b/wallet/db.c @@ -197,6 +197,23 @@ bool PRINTF_FMT(3, 4) return true; } +bool db_exec_prepared_mayfail_(const char *caller, struct db *db, sqlite3_stmt *stmt) +{ + if (db->in_transaction && db->err) { + goto fail; + } + + if (sqlite3_step(stmt) != SQLITE_DONE) { + goto fail; + } + + sqlite3_finalize(stmt); + return true; +fail: + sqlite3_finalize(stmt); + return false; +} + sqlite3_stmt *PRINTF_FMT(3, 4) db_query(const char *caller, struct db *db, const char *fmt, ...) { diff --git a/wallet/db.h b/wallet/db.h index d5d7da1df..a5c047c98 100644 --- a/wallet/db.h +++ b/wallet/db.h @@ -112,6 +112,15 @@ sqlite3_stmt *db_prepare_(const char *caller, struct db *db, const char *query); #define db_exec_prepared(db,stmt) db_exec_prepared_(__func__,db,stmt) bool db_exec_prepared_(const char *caller, struct db *db, sqlite3_stmt *stmt); +/** + * db_exec_prepared_mayfail - db_exec_prepared, but don't set db->err if it fails. + */ +#define db_exec_prepared_mayfail(db,stmt) \ + db_exec_prepared_mayfail_(__func__,db,stmt) +bool db_exec_prepared_mayfail_(const char *caller, + struct db *db, + sqlite3_stmt *stmt); + bool sqlite3_bind_short_channel_id(sqlite3_stmt *stmt, int col, const struct short_channel_id *id); bool sqlite3_column_short_channel_id(sqlite3_stmt *stmt, int col,