libeufin

Integration and sandbox testing for FinTech APIs and data formats
Log | Files | Refs | Submodules | README | LICENSE

commit ad56730b3bb511d51f2994e0152937138012560c
parent b6811eb3c955ab4dedd90275c953c507d45a463e
Author: Antoine A <>
Date:   Fri, 24 Apr 2026 10:18:39 +0200

common: fix some SQL bugs

Diffstat:
Mdatabase-versioning/libeufin-bank-procedures.sql | 8+++-----
Mdatabase-versioning/libeufin-nexus-procedures.sql | 11+++--------
2 files changed, 6 insertions(+), 13 deletions(-)

diff --git a/database-versioning/libeufin-bank-procedures.sql b/database-versioning/libeufin-bank-procedures.sql @@ -222,7 +222,7 @@ WITH computed AS ( FROM computed; IF in_max_amount.val < out_max_amount.val - OR (in_max_amount.val = out_max_amount.val OR in_max_amount.frac < out_max_amount.frac) THEN + OR (in_max_amount.val = out_max_amount.val AND in_max_amount.frac < out_max_amount.frac) THEN out_max_amount = in_max_amount; END IF; END $$; @@ -575,7 +575,7 @@ IF has_fee THEN debtor_payto, debtor_name, 'wire transfer fees for tx ' || out_debit_row_id, - in_amount, + in_wire_transfer_fees, in_timestamp, 'credit', admin_account_id @@ -1479,7 +1479,6 @@ DECLARE wallet_bank_account_local INT8; amount_local taler_amount; exchange_bank_account_id INT8; - tx_row_id INT8; local_type taler_incoming_type; BEGIN -- Load account info @@ -1519,8 +1518,7 @@ SELECT -- not checking for accounts existence, as it was done above. transfer.out_balance_insufficient, transfer.out_bad_amount, transfer.out_reserve_pub_reuse - out_credit_row_id - INTO out_balance_insufficient, out_bad_amount, out_reserve_pub_reuse, tx_row_id + INTO out_balance_insufficient, out_bad_amount, out_reserve_pub_reuse FROM make_incoming( exchange_bank_account_id, wallet_bank_account_local, diff --git a/database-versioning/libeufin-nexus-procedures.sql b/database-versioning/libeufin-nexus-procedures.sql @@ -503,7 +503,7 @@ BEGIN SELECT (amount != in_amount OR credit_payto != in_credit_account_payto OR exchange_base_url != in_exchange_base_url - OR exchange_base_url != in_exchange_base_url + OR metadata != in_metadata OR wtid != in_wtid) ,transfer_operations.initiated_outgoing_transaction_id, initiation_time INTO out_request_uid_reuse, out_tx_row_id, out_timestamp @@ -559,18 +559,12 @@ CREATE FUNCTION batch_outgoing_transactions( RETURNS void LANGUAGE plpgsql AS $$ DECLARE -pending BOOLEAN; batch_id INT8; local_sum taler_amount DEFAULT (0, 0)::taler_amount; tx record; BEGIN -IF require_ack THEN - pending = EXISTS(SELECT FROM initiated_outgoing_transactions WHERE initiated_outgoing_batch_id IS NULL AND NOT awaiting_ack); -ELSE - pending = EXISTS(SELECT FROM initiated_outgoing_transactions WHERE initiated_outgoing_batch_id IS NULL); -END IF; -- Create a new batch only if some transactions are not batched -IF (pending) THEN +IF EXISTS(SELECT FROM initiated_outgoing_transactions WHERE initiated_outgoing_batch_id IS NULL AND (NOT require_ack OR NOT awaiting_ack)) THEN -- Create batch INSERT INTO initiated_outgoing_batches (creation_date, message_id) VALUES (in_timestamp, batch_ebics_id) @@ -579,6 +573,7 @@ IF (pending) THEN FOR tx IN UPDATE initiated_outgoing_transactions SET initiated_outgoing_batch_id=batch_id WHERE initiated_outgoing_batch_id IS NULL + AND (NOT require_ack OR NOT awaiting_ack) RETURNING amount LOOP SELECT sum.val, sum.frac