From c1aab035e41147450b7cbe91a2f3d204a906d0ea Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Tue, 13 Apr 2021 10:32:47 -0500 Subject: [PATCH] Do not try query when values is empty If there are no values to query with, then the SQL will be invalid and throw an error, so just return empty for that case. --- config.ru | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/config.ru b/config.ru index ac9fde5..f265ccd 100644 --- a/config.ru +++ b/config.ru @@ -170,16 +170,23 @@ end class UnknownTransactions def self.from(customer_id, address, tx_hashes) + self.for( + customer_id, + fetch_rows_for(address, tx_hashes).map { |row| row["transaction_id"] } + ) + end + + def self.fetch_rows_for(address, tx_hashes) values = tx_hashes.map do |tx_hash| "('#{DB.escape_string(tx_hash)}/#{DB.escape_string(address)}')" end - rows = DB.exec_params(<<-SQL) + return [] unless values + DB.exec_params(<<-SQL) SELECT transaction_id FROM (VALUES #{values.join(',')}) AS t(transaction_id) LEFT JOIN transactions USING (transaction_id) WHERE transactions.transaction_id IS NULL SQL - self.for(customer_id, rows.map { |row| row["transaction_id"] }) end def self.for(customer_id, transaction_ids) -- 2.45.2