mirror of
https://github.com/aljazceru/lightning.git
synced 2026-01-05 07:14:36 +01:00
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>
This commit is contained in:
committed by
Rusty Russell
parent
f78205f30f
commit
b267b24c08
16
wallet/db.c
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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user