From 093f5bfbecf946933a3c27aaa5a6dab34e7eee09 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Thu, 25 Jul 2019 22:47:44 +0200 Subject: [PATCH] db: Switch to new DB asbtraction for DB migrations These do not require the ability to iterate over the result, hence they can be migrated already. Signed-off-by: Christian Decker --- wallet/db.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/wallet/db.c b/wallet/db.c index 1e2f7958a..15929e608 100644 --- a/wallet/db.c +++ b/wallet/db.c @@ -878,8 +878,12 @@ static void db_migrate(struct lightningd *ld, struct db *db, struct log *log) while (current < available) { current++; - if (dbmigrations[current].sql) - db_exec(__func__, db, "%s", dbmigrations[current].sql); + if (dbmigrations[current].sql) { + struct db_stmt *stmt = + db_prepare_v2(db, dbmigrations[current].sql); + db_exec_prepared_v2(stmt); + db_stmt_free(stmt); + } if (dbmigrations[current].func) dbmigrations[current].func(ld, db); } @@ -1270,10 +1274,14 @@ void sqlite3_bind_amount_sat(sqlite3_stmt *stmt, int col, /* Will apply the current config fee settings to all channels */ void migrate_pr2342_feerate_per_channel(struct lightningd *ld, struct db *db) { - db_exec(__func__, db, - "UPDATE channels SET feerate_base = %u, feerate_ppm = %u;", - ld->config.fee_base, - ld->config.fee_per_satoshi); + struct db_stmt *stmt = db_prepare_v2( + db, SQL("UPDATE channels SET feerate_base = ?, feerate_ppm = ?;")); + + db_bind_int(stmt, 0, ld->config.fee_base); + db_bind_int(stmt, 1, ld->config.fee_per_satoshi); + + db_exec_prepared_v2(stmt); + db_stmt_free(stmt); } void sqlite3_bind_timeabs(sqlite3_stmt *stmt, int col, struct timeabs t)