db: add generic warn/error function.

This avoids the mess where we override db_fatal for teqsts, and keeps it
generic.

Also allows us to get rid of one #if DEVELOPER, and an ugly global for
bookkeeper.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2023-06-30 04:53:08 +09:30
parent bef137209d
commit 04f485aee0
15 changed files with 149 additions and 209 deletions

View File

@@ -6,6 +6,7 @@
#include <ccan/strset/strset.h>
#include <common/autodata.h>
#include <common/utils.h>
#include <stdarg.h>
/**
* Macro to annotate a named SQL query.
@@ -35,6 +36,10 @@ struct db {
/* DB-specific context */
void *conn;
/* function to log warnings, or fail (if fatal == true). vprintf-style */
void (*errorfn)(void *arg, bool fatal, const char *fmt, va_list ap);
void *errorfn_arg;
/* The configuration for the current database driver */
const struct db_config *config;
@@ -183,9 +188,6 @@ struct db_config {
const char **colnames, size_t num_cols);
};
void db_fatal(const char *fmt, ...)
PRINTF_FMT(1, 2);
/* Provide a way for DB backends to register themselves */
AUTODATA_TYPE(db_backends, struct db_config);