From b1956aa73a533702ccbc3d7713ea90dd5ae44b9b Mon Sep 17 00:00:00 2001 From: Anders Betts Date: Mon, 21 Sep 2026 09:47:50 +0200 Subject: commands: db_row_json and db_exec_bound helpers Co-Authored-By: Claude Opus 5 --- src/cmd_util.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/cmd_util.h') diff --git a/src/cmd_util.h b/src/cmd_util.h index ccab9f4..6187efe 100644 --- a/src/cmd_util.h +++ b/src/cmd_util.h @@ -25,6 +25,23 @@ yyjson_mut_val *failf(struct req *r, const char *code, const char *fmt, ...) yyjson_mut_val *db_error(struct req *r); yyjson_mut_val *db_sqlite_error(struct req *r); void bind_text_or_null(sqlite3_stmt *st, int idx, const char *s); +/* spec: "id:i,name:s,active:b" — i int, s text ("" for NULL), b bool, + * n nullable text (JSON null for NULL), r nullable int; columns from 0. */ +yyjson_mut_val *db_row_json(yyjson_mut_doc *doc, sqlite3_stmt *st, + const char *spec); +/* types: one letter per bind — i int64_t, s const char *, n nullable + * const char *. Returns the statement bound at ?1.., NULL on prepare error. */ +sqlite3_stmt *db_prepare_bound(sqlite3 *db, const char *sql, const char *types, + ...); +/* 0 on SQLITE_DONE, -1 when prepare fails, else the step result. */ +int db_exec_bound(sqlite3 *db, const char *sql, const char *types, ...); +/* db_exec_bound with the request's error set: db_error on prepare failure, + * db_sqlite_error on any other step result. Returns 0 on success. */ +int req_exec(struct req *r, const char *sql, const char *types, ...); +/* {"items":[db_row_json(spec) per row]} for a bound SELECT; NULL with + * db_error set when prepare fails. */ +yyjson_mut_val *req_list(struct req *r, const char *sql, const char *spec, + const char *types, ...); int mkdir_p(const char *path, mode_t mode); yyjson_mut_val *json_to_mut(yyjson_mut_doc *doc, const char *json); int is_digits(const char *s); -- cgit v1.3