From a1c20bfc87298c6e04f159311206eca66c958115 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 14 Jul 2023 09:58:45 +0930 Subject: [PATCH] db: implement BIND_NEXT for autocounting. Signed-off-by: Rusty Russell --- db/bindings.c | 11 ++++++++++- db/bindings.h | 3 +++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/db/bindings.c b/db/bindings.c index a9ca4c630..1b223e66d 100644 --- a/db/bindings.c +++ b/db/bindings.c @@ -18,7 +18,16 @@ static int check_bind_pos(struct db_stmt *stmt, int pos) { - assert(pos == ++stmt->bind_pos); + if (pos == BIND_NEXT) { + /* Don't mix BIND_NEXT with other args! */ + assert(stmt->bindings[stmt->bind_pos+1].type == DB_BINDING_UNINITIALIZED); + return ++stmt->bind_pos; + } + + /* Don't mix BIND_NEXT with other args! */ + assert(stmt->bind_pos == -1); + assert(pos >= 0); + assert(pos < tal_count(stmt->bindings)); return pos; } diff --git a/db/bindings.h b/db/bindings.h index 4a5556eb0..c946cbb7a 100644 --- a/db/bindings.h +++ b/db/bindings.h @@ -17,6 +17,9 @@ struct onionreply; struct wally_psbt; struct wally_tx; +/* Magic pos argument meaning "the next field" */ +#define BIND_NEXT -77 + int db_col_is_null(struct db_stmt *stmt, const char *colname); void db_bind_int(struct db_stmt *stmt, int pos, int val);