Skip to content

Commit a1c20bf

Browse files
committed
db: implement BIND_NEXT for autocounting.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent b7b3cbc commit a1c20bf

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

db/bindings.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,16 @@
1818

1919
static int check_bind_pos(struct db_stmt *stmt, int pos)
2020
{
21-
assert(pos == ++stmt->bind_pos);
21+
if (pos == BIND_NEXT) {
22+
/* Don't mix BIND_NEXT with other args! */
23+
assert(stmt->bindings[stmt->bind_pos+1].type == DB_BINDING_UNINITIALIZED);
24+
return ++stmt->bind_pos;
25+
}
26+
27+
/* Don't mix BIND_NEXT with other args! */
28+
assert(stmt->bind_pos == -1);
29+
assert(pos >= 0);
30+
assert(pos < tal_count(stmt->bindings));
2231
return pos;
2332
}
2433

db/bindings.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ struct onionreply;
1717
struct wally_psbt;
1818
struct wally_tx;
1919

20+
/* Magic pos argument meaning "the next field" */
21+
#define BIND_NEXT -77
22+
2023
int db_col_is_null(struct db_stmt *stmt, const char *colname);
2124

2225
void db_bind_int(struct db_stmt *stmt, int pos, int val);

0 commit comments

Comments
 (0)