mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-24 01:24:26 +01:00
db: add optional column string helper, and make db_col amounts return sat/msat.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -319,6 +319,17 @@ char *db_col_strdup(const tal_t *ctx,
|
||||
return tal_strdup(ctx, (char *)stmt->db->config->column_text_fn(stmt, col));
|
||||
}
|
||||
|
||||
char *db_col_strdup_optional(const tal_t *ctx,
|
||||
struct db_stmt *stmt,
|
||||
const char *colname)
|
||||
{
|
||||
size_t col = db_query_colnum(stmt, colname);
|
||||
if (db_column_is_null(stmt, col))
|
||||
return NULL;
|
||||
|
||||
return tal_strdup(ctx, (char *)stmt->db->config->column_text_fn(stmt, col));
|
||||
}
|
||||
|
||||
void db_col_preimage(struct db_stmt *stmt, const char *colname,
|
||||
struct preimage *preimage)
|
||||
{
|
||||
@@ -516,15 +527,14 @@ void db_col_amount_msat_or_default(struct db_stmt *stmt,
|
||||
msat->millisatoshis = db_col_u64(stmt, colname); /* Raw: low level function */
|
||||
}
|
||||
|
||||
void db_col_amount_msat(struct db_stmt *stmt, const char *colname,
|
||||
struct amount_msat *msat)
|
||||
struct amount_msat db_col_amount_msat(struct db_stmt *stmt, const char *colname)
|
||||
{
|
||||
msat->millisatoshis = db_col_u64(stmt, colname); /* Raw: low level function */
|
||||
return amount_msat(db_col_u64(stmt, colname));
|
||||
}
|
||||
|
||||
void db_col_amount_sat(struct db_stmt *stmt, const char *colname, struct amount_sat *sat)
|
||||
struct amount_sat db_col_amount_sat(struct db_stmt *stmt, const char *colname)
|
||||
{
|
||||
sat->satoshis = db_col_u64(stmt, colname); /* Raw: low level function */
|
||||
return amount_sat(db_col_u64(stmt, colname));
|
||||
}
|
||||
|
||||
struct json_escape *db_col_json_escape(const tal_t *ctx,
|
||||
|
||||
Reference in New Issue
Block a user