Browse Source

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>
ppa-0.6.1
Rusty Russell 7 years ago
committed by Christian Decker
parent
commit
b148b89baf
  1. 17
      wallet/db.c
  2. 9
      wallet/db.h

17
wallet/db.c

@ -197,6 +197,23 @@ bool PRINTF_FMT(3, 4)
return true; 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) sqlite3_stmt *PRINTF_FMT(3, 4)
db_query(const char *caller, struct db *db, const char *fmt, ...) db_query(const char *caller, struct db *db, const char *fmt, ...)
{ {

9
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) #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); 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, bool sqlite3_bind_short_channel_id(sqlite3_stmt *stmt, int col,
const struct short_channel_id *id); const struct short_channel_id *id);
bool sqlite3_column_short_channel_id(sqlite3_stmt *stmt, int col, bool sqlite3_column_short_channel_id(sqlite3_stmt *stmt, int col,

Loading…
Cancel
Save