db: keep in_transaction as a counter, so we can nest commits.

Otherwise we find ourselves outside a commitment.  This is a bandaid
until we remove nested commitments again at the end of this series.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2017-11-01 11:40:48 +10:30 committed by Christian Decker
parent 77789bb705
commit 5e46af64fc
2 changed files with 4 additions and 3 deletions

View File

@ -235,6 +235,7 @@ bool db_begin_transaction(struct db *db)
assert(db->in_transaction);
return db->in_transaction;
}
db->in_transaction++;
return false;
}
@ -242,7 +243,7 @@ bool db_commit_transaction(struct db *db)
{
assert(db->in_transaction);
bool ret = db_exec(__func__, db, "COMMIT;");
db->in_transaction = false;
db->in_transaction--;
return ret;
}
@ -250,7 +251,7 @@ bool db_rollback_transaction(struct db *db)
{
assert(db->in_transaction);
bool ret = db_exec(__func__, db, "ROLLBACK;");
db->in_transaction = false;
db->in_transaction--;
return ret;
}

View File

@ -15,7 +15,7 @@
struct db {
char *filename;
bool in_transaction;
unsigned int in_transaction;
const char *err;
sqlite3 *sql;
};