Browse Source

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.
ppa-0.6.1
Rusty Russell 7 years ago
committed by Christian Decker
parent
commit
1f7e370fda
  1. 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…
Cancel
Save