mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 05:12:45 +01:00
db: rollback transaction if we had an error.
This is temporary; we'll eventually fail on error. However, since db_exec() is a NOOP if we have an error, we need to do something.
This commit is contained in:
parent
360aa15e4d
commit
1f7e370fda
18
wallet/db.c
18
wallet/db.c
@ -236,8 +236,24 @@ bool db_begin_transaction(struct db *db)
|
||||
|
||||
bool db_commit_transaction(struct db *db)
|
||||
{
|
||||
bool ret;
|
||||
|
||||
assert(db->in_transaction);
|
||||
bool ret = db_exec(__func__, db, "COMMIT;");
|
||||
if (db->err) {
|
||||
char *errmsg;
|
||||
int err;
|
||||
|
||||
/* Do this manually: db_exec is a NOOP with db->err */
|
||||
err = sqlite3_exec(db->sql, "ROLLBACK;", NULL, NULL, &errmsg);
|
||||
if (err != SQLITE_OK) {
|
||||
db->err = tal_fmt(db, "%s then ROLLBACK failed:%s:%s",
|
||||
db->err, sqlite3_errstr(err), errmsg);
|
||||
sqlite3_free(errmsg);
|
||||
}
|
||||
ret = false;
|
||||
} else {
|
||||
ret = db_exec(__func__, db, "COMMIT;");
|
||||
}
|
||||
db->in_transaction--;
|
||||
return ret;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user