mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-23 17:14:22 +01:00
wallet: Expose transactional interface for db
This commit is contained in:
committed by
Rusty Russell
parent
5396335363
commit
19a4e7f542
22
wallet/db.c
22
wallet/db.c
@@ -87,14 +87,7 @@ static void db_clear_error(struct db *db)
|
|||||||
|
|
||||||
static void close_db(struct db *db) { sqlite3_close(db->sql); }
|
static void close_db(struct db *db) { sqlite3_close(db->sql); }
|
||||||
|
|
||||||
/**
|
bool db_begin_transaction(struct db *db)
|
||||||
* db_begin_transaction - Begin a transaction
|
|
||||||
*
|
|
||||||
* We do not support nesting multiple transactions, so make sure that
|
|
||||||
* we are not in a transaction when calling this. Returns true if we
|
|
||||||
* succeeded in starting a transaction.
|
|
||||||
*/
|
|
||||||
static bool db_begin_transaction(struct db *db)
|
|
||||||
{
|
{
|
||||||
assert(!db->in_transaction);
|
assert(!db->in_transaction);
|
||||||
/* Clear any errors from previous transactions and
|
/* Clear any errors from previous transactions and
|
||||||
@@ -104,13 +97,7 @@ static bool db_begin_transaction(struct db *db)
|
|||||||
return db->in_transaction;
|
return db->in_transaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
bool db_commit_transaction(struct db *db)
|
||||||
* db_commit_transaction - Commit a running transaction
|
|
||||||
*
|
|
||||||
* Requires that we are currently in a transaction. Returns whether
|
|
||||||
* the commit was successful.
|
|
||||||
*/
|
|
||||||
static bool db_commit_transaction(struct db *db)
|
|
||||||
{
|
{
|
||||||
assert(db->in_transaction);
|
assert(db->in_transaction);
|
||||||
bool ret = db_exec(__func__, db, "COMMIT;");
|
bool ret = db_exec(__func__, db, "COMMIT;");
|
||||||
@@ -118,10 +105,7 @@ static bool db_commit_transaction(struct db *db)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
bool db_rollback_transaction(struct db *db)
|
||||||
* db_rollback_transaction - Whoops... undo! undo!
|
|
||||||
*/
|
|
||||||
static bool db_rollback_transaction(struct db *db)
|
|
||||||
{
|
{
|
||||||
assert(db->in_transaction);
|
assert(db->in_transaction);
|
||||||
bool ret = db_exec(__func__, db, "ROLLBACK;");
|
bool ret = db_exec(__func__, db, "ROLLBACK;");
|
||||||
|
|||||||
22
wallet/db.h
22
wallet/db.h
@@ -35,4 +35,26 @@ sqlite3_stmt *PRINTF_FMT(3, 4)
|
|||||||
bool PRINTF_FMT(3, 4)
|
bool PRINTF_FMT(3, 4)
|
||||||
db_exec(const char *caller, struct db *db, const char *fmt, ...);
|
db_exec(const char *caller, struct db *db, const char *fmt, ...);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* db_begin_transaction - Begin a transaction
|
||||||
|
*
|
||||||
|
* We do not support nesting multiple transactions, so make sure that
|
||||||
|
* we are not in a transaction when calling this. Returns true if we
|
||||||
|
* succeeded in starting a transaction.
|
||||||
|
*/
|
||||||
|
bool db_begin_transaction(struct db *db);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* db_commit_transaction - Commit a running transaction
|
||||||
|
*
|
||||||
|
* Requires that we are currently in a transaction. Returns whether
|
||||||
|
* the commit was successful.
|
||||||
|
*/
|
||||||
|
bool db_commit_transaction(struct db *db);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* db_rollback_transaction - Whoops... undo! undo!
|
||||||
|
*/
|
||||||
|
bool db_rollback_transaction(struct db *db);
|
||||||
|
|
||||||
#endif /* WALLET_DB_H */
|
#endif /* WALLET_DB_H */
|
||||||
|
|||||||
Reference in New Issue
Block a user