mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-15 11:59:16 +01:00
db: improve db_col_* APIs.
1. db_col_text becomes db_col_strdup, which is what is usually wanted. 2. db_col_short_channel_id becomes db_col_short_channel_id_str, to emphasize that it stores in string form. Modern versions should store u64. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
5b482eb04b
commit
befab73070
2 changed files with 11 additions and 6 deletions
11
wallet/db.c
11
wallet/db.c
|
@ -2230,7 +2230,9 @@ const void *db_col_blob(struct db_stmt *stmt, const char *colname)
|
|||
return stmt->db->config->column_blob_fn(stmt, col);
|
||||
}
|
||||
|
||||
const unsigned char *db_col_text(struct db_stmt *stmt, const char *colname)
|
||||
char *db_col_strdup(const tal_t *ctx,
|
||||
struct db_stmt *stmt,
|
||||
const char *colname)
|
||||
{
|
||||
size_t col = db_query_colnum(stmt, colname);
|
||||
|
||||
|
@ -2238,7 +2240,7 @@ const unsigned char *db_col_text(struct db_stmt *stmt, const char *colname)
|
|||
log_broken(stmt->db->log, "Accessing a null column %s/%zu in query %s", colname, col, stmt->query->query);
|
||||
return NULL;
|
||||
}
|
||||
return stmt->db->config->column_text_fn(stmt, col);
|
||||
return tal_strdup(ctx, (char *)stmt->db->config->column_text_fn(stmt, col));
|
||||
}
|
||||
|
||||
void db_col_preimage(struct db_stmt *stmt, const char *colname,
|
||||
|
@ -2295,8 +2297,9 @@ void db_col_pubkey(struct db_stmt *stmt,
|
|||
assert(ok);
|
||||
}
|
||||
|
||||
bool db_col_short_channel_id(struct db_stmt *stmt, const char *colname,
|
||||
struct short_channel_id *dest)
|
||||
/* Yes, we put this in as a string. Past mistakes; do not use! */
|
||||
bool db_col_short_channel_id_str(struct db_stmt *stmt, const char *colname,
|
||||
struct short_channel_id *dest)
|
||||
{
|
||||
size_t col = db_query_colnum(stmt, colname);
|
||||
const char *source = db_column_blob(stmt, col);
|
||||
|
|
|
@ -190,7 +190,9 @@ int db_col_int(struct db_stmt *stmt, const char *colname);
|
|||
size_t db_col_bytes(struct db_stmt *stmt, const char *colname);
|
||||
int db_col_is_null(struct db_stmt *stmt, const char *colname);
|
||||
const void* db_col_blob(struct db_stmt *stmt, const char *colname);
|
||||
const unsigned char *db_col_text(struct db_stmt *stmt, const char *colname);
|
||||
char *db_col_strdup(const tal_t *ctx,
|
||||
struct db_stmt *stmt,
|
||||
const char *colname);
|
||||
void db_col_preimage(struct db_stmt *stmt, const char *colname, struct preimage *preimage);
|
||||
void db_col_amount_msat(struct db_stmt *stmt, const char *colname, struct amount_msat *msat);
|
||||
void db_col_amount_sat(struct db_stmt *stmt, const char *colname, struct amount_sat *sat);
|
||||
|
@ -207,7 +209,7 @@ struct node_id *db_col_node_id_arr(const tal_t *ctx, struct db_stmt *stmt,
|
|||
const char *colname);
|
||||
void db_col_pubkey(struct db_stmt *stmt, const char *colname,
|
||||
struct pubkey *p);
|
||||
bool db_col_short_channel_id(struct db_stmt *stmt, const char *colname,
|
||||
bool db_col_short_channel_id_str(struct db_stmt *stmt, const char *colname,
|
||||
struct short_channel_id *dest);
|
||||
struct short_channel_id *
|
||||
db_col_short_channel_id_arr(const tal_t *ctx, struct db_stmt *stmt, const char *colname);
|
||||
|
|
Loading…
Add table
Reference in a new issue