mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-22 14:42:40 +01:00
db_exec_mayfail: variant of db_exec where we actually expect an error.
There's one caller where db_exec can actually fail due to constraints, and we rely on it. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
1f7e370fda
commit
b148b89baf
2 changed files with 26 additions and 0 deletions
17
wallet/db.c
17
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, ...)
|
||||
{
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Reference in a new issue