~singpolyma/jmp-pay

c1aab035e41147450b7cbe91a2f3d204a906d0ea — Stephen Paul Weber 1 year, 3 months ago 431d153
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.
1 files changed, 9 insertions(+), 2 deletions(-)

M config.ru
M config.ru => config.ru +9 -2
@@ 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)