From 3e30b67e0ca09fcca588218518326a69328d240e Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Tue, 19 Mar 2024 12:04:16 -0700 Subject: [PATCH] Improved casting code --- lib/blazer/adapters/sql_adapter.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/blazer/adapters/sql_adapter.rb b/lib/blazer/adapters/sql_adapter.rb index 154158b86..38c3d4414 100644 --- a/lib/blazer/adapters/sql_adapter.rb +++ b/lib/blazer/adapters/sql_adapter.rb @@ -29,8 +29,15 @@ def run_statement(statement, comment, bind_params = []) end columns = result.columns - result.rows.each do |untyped_row| - rows << (result.column_types.empty? ? untyped_row : columns.each_with_index.map { |c, i| untyped_row[i] && result.column_types[c] ? result.column_types[c].send(:cast_value, untyped_row[i]) : untyped_row[i] }) + rows = result.rows + if result.column_types.any? + types = columns.map { |c| result.column_types[c] } + rows = + rows.map do |row| + row.map.with_index do |v, i| + v && (t = types[i]) ? t.send(:cast_value, v) : v + end + end end # fix for non-ASCII column names and charts