db: Migrate to DB abstraction layer in db.c

Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
Christian Decker
2019-08-13 16:00:46 +02:00
committed by Rusty Russell
parent 716a3b11a5
commit c68efdfcf4
3 changed files with 64 additions and 93 deletions

View File

@@ -78,7 +78,9 @@ static bool test_empty_db_migrate(struct lightningd *ld)
static bool test_primitives(void)
{
struct db_stmt *stmt;
struct db *db = create_test_db();
db_err = NULL;
db_begin_transaction(db);
CHECK(db->in_transaction);
db_commit_transaction(db);
@@ -87,11 +89,15 @@ static bool test_primitives(void)
db_commit_transaction(db);
db_begin_transaction(db);
db_exec(__func__, db, "SELECT name FROM sqlite_master WHERE type='table';");
stmt = db_prepare_v2(db, SQL("SELECT name FROM sqlite_master WHERE type='table';"));
CHECK_MSG(db_exec_prepared_v2(stmt), "db_exec_prepared must succeed");
CHECK_MSG(!db_err, "Simple correct SQL command");
tal_free(stmt);
db_exec(__func__, db, "not a valid SQL statement");
stmt = db_prepare_v2(db, SQL("not a valid SQL statement"));
CHECK_MSG(!db_exec_prepared_v2(stmt), "db_exec_prepared must fail");
CHECK_MSG(db_err, "Failing SQL command");
tal_free(stmt);
db_err = tal_free(db_err);
db_commit_transaction(db);
CHECK(!db->in_transaction);