db: print nice message and not just backtrace on bad column name.

Happens more than I expected!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2023-04-10 09:43:56 +09:30
parent c45eb62b57
commit 8493ee5e1a

View file

@ -21,9 +21,13 @@ size_t db_query_colnum(const struct db_stmt *stmt,
assert(stmt->query->colnames != NULL);
col = hash_djb2(colname) % stmt->query->num_colnames;
/* Will crash on NULL, which is the Right Thing */
while (!streq(stmt->query->colnames[col].sqlname,
colname)) {
for (;;) {
const char *n = stmt->query->colnames[col].sqlname;
if (!n)
db_fatal("Unknown column name %s in query %s",
colname, stmt->query->query);
if (streq(n, colname))
break;
col = (col + 1) % stmt->query->num_colnames;
}