Skip to content

Commit c1090c1

Browse files
committed
Improved SQL adapter
1 parent 728d348 commit c1090c1

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

lib/blazer/adapters/sql_adapter.rb

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,30 @@ def run_statement(statement, comment, bind_params = [])
2121
error = nil
2222

2323
begin
24-
result = nil
24+
types = []
2525
in_transaction do
2626
set_timeout(data_source.timeout) if data_source.timeout
2727
binds = bind_params.map { |v| ActiveRecord::Relation::QueryAttribute.new(nil, v, ActiveRecord::Type::Value.new) }
2828
if sqlite?
2929
type_map = connection_model.connection.send(:type_map)
3030
connection_model.connection.raw_connection.prepare("#{statement} /*#{comment}*/") do |stmt|
3131
stmt.bind_params(connection_model.connection.send(:type_casted_binds, binds))
32-
types = stmt.columns.zip(stmt.types).to_h { |c, t| [c, type_map.lookup(t)] }
33-
result = ActiveRecord::Result.new(stmt.columns, stmt.to_a, types)
32+
columns = stmt.columns
33+
rows = stmt.to_a
34+
types = stmt.types.map { |t| type_map.lookup(t) }
3435
end
3536
else
3637
result = connection_model.connection.select_all("#{statement} /*#{comment}*/", nil, binds)
38+
columns = result.columns
39+
rows = result.rows
40+
if result.column_types.any?
41+
types = columns.size.times.map { |i| result.column_types[i] }
42+
end
3743
end
3844
end
3945

40-
columns = result.columns
41-
rows = result.rows
42-
4346
# cast values
44-
if result.column_types.any?
45-
types = columns.map { |c| result.column_types[c] }
47+
if types.any?
4648
rows =
4749
rows.map do |row|
4850
row.map.with_index do |v, i|

0 commit comments

Comments
 (0)