Skip to content

Commit 3e30b67

Browse files
committed
Improved casting code
1 parent bd06aab commit 3e30b67

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

lib/blazer/adapters/sql_adapter.rb

+9-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,15 @@ def run_statement(statement, comment, bind_params = [])
2929
end
3030

3131
columns = result.columns
32-
result.rows.each do |untyped_row|
33-
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] })
32+
rows = result.rows
33+
if result.column_types.any?
34+
types = columns.map { |c| result.column_types[c] }
35+
rows =
36+
rows.map do |row|
37+
row.map.with_index do |v, i|
38+
v && (t = types[i]) ? t.send(:cast_value, v) : v
39+
end
40+
end
3441
end
3542

3643
# fix for non-ASCII column names and charts

0 commit comments

Comments
 (0)