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:
Rusty Russell 2017-11-01 11:40:48 +10:30 committed by Christian Decker
parent 360aa15e4d
commit 1f7e370fda
1 changed files with 17 additions and 1 deletions

View File

@ -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;
}