mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
db: Strengthen some null-checks on queries
sqlite3 will just report 0 for anything that it thinks should be numeric, or is accessed using a numeric accessor. Postgres does not, so we need to check for is_null before trying to read it. Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
committed by
Rusty Russell
parent
07f8d9046a
commit
1f935cbd85
@@ -2829,8 +2829,10 @@ void wallet_transaction_annotate(struct wallet *w,
|
|||||||
fatal("Attempting to annotate a transaction we don't have: %s",
|
fatal("Attempting to annotate a transaction we don't have: %s",
|
||||||
type_to_string(tmpctx, struct bitcoin_txid, txid));
|
type_to_string(tmpctx, struct bitcoin_txid, txid));
|
||||||
|
|
||||||
|
if (!db_column_is_null(stmt, 0))
|
||||||
type |= db_column_int(stmt, 0);
|
type |= db_column_int(stmt, 0);
|
||||||
if (channel_id == 0)
|
|
||||||
|
if (channel_id == 0 && !db_column_is_null(stmt, 1))
|
||||||
channel_id = db_column_u64(stmt, 1);
|
channel_id = db_column_u64(stmt, 1);
|
||||||
|
|
||||||
tal_free(stmt);
|
tal_free(stmt);
|
||||||
@@ -3085,7 +3087,7 @@ struct amount_msat wallet_total_forward_fees(struct wallet *w)
|
|||||||
bool res;
|
bool res;
|
||||||
|
|
||||||
stmt = db_prepare_v2(w->db, SQL("SELECT"
|
stmt = db_prepare_v2(w->db, SQL("SELECT"
|
||||||
" SUM(in_msatoshi - out_msatoshi) "
|
" CAST(COALESCE(SUM(in_msatoshi - out_msatoshi), 0) AS BIGINT)"
|
||||||
"FROM forwarded_payments "
|
"FROM forwarded_payments "
|
||||||
"WHERE state = ?;"));
|
"WHERE state = ?;"));
|
||||||
db_bind_int(stmt, 0, wallet_forward_status_in_db(FORWARD_SETTLED));
|
db_bind_int(stmt, 0, wallet_forward_status_in_db(FORWARD_SETTLED));
|
||||||
|
|||||||
Reference in New Issue
Block a user