Browse Source

db: db_exec_prepared takes ownership of the statement

Technically it's the caller that'll own the statement, but it is nice
to have db_exec_prepared dispose of it.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
ppa-0.6.1
Christian Decker 7 years ago
committed by Rusty Russell
parent
commit
b267b24c08
  1. 16
      wallet/db.c
  2. 3
      wallet/db.h

16
wallet/db.c

@ -150,17 +150,23 @@ sqlite3_stmt *db_prepare_(const char *caller, struct db *db, const char *query)
bool db_exec_prepared_(const char *caller, struct db *db, sqlite3_stmt *stmt)
{
if (db->in_transaction && db->err)
return false;
if (db->in_transaction && db->err) {
goto fail;
}
db_clear_error(db);
if (sqlite3_step(stmt) != SQLITE_DONE) {
db->err =
tal_fmt(db, "%s: %s", caller, sqlite3_errmsg(db->sql));
return false;
} else {
return true;
goto fail;
}
sqlite3_finalize(stmt);
return true;
fail:
sqlite3_finalize(stmt);
return false;
}
bool PRINTF_FMT(3, 4)

3
wallet/db.h

@ -102,7 +102,8 @@ sqlite3_stmt *db_prepare_(const char *caller, struct db *db, const char *query);
* all non-null variables using the `sqlite3_bind_*` functions, it can
* be executed with this function. It is a small, transaction-aware,
* wrapper around `sqlite3_step`, that also sets `db->err` if the
* execution fails.
* execution fails. This will take ownership of `stmt` and will free
* it before returning.
*
* @db: The database to execute on
* @stmt: The prepared statement to execute

Loading…
Cancel
Save