Skip to content

Commit aae3f54

Browse files
committed
Fixed types for SQLite - resolves #494 and resolves #495
1 parent b0f69fd commit aae3f54

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## 3.1.1 (unreleased)
22

3+
- Fixes types for SQLite
34
- Fixed table preview and schema page for SQLite
45

56
## 3.1.0 (2024-10-14)

lib/blazer/adapters/sql_adapter.rb

+11-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,17 @@ def run_statement(statement, comment, bind_params = [])
2424
result = nil
2525
in_transaction do
2626
set_timeout(data_source.timeout) if data_source.timeout
27-
binds = bind_params.map { |v| ActiveRecord::Relation::QueryAttribute.new(nil, v, ActiveRecord::Type::Value.new) }
28-
result = connection_model.connection.select_all("#{statement} /*#{comment}*/", nil, binds)
27+
if sqlite?
28+
type_map = connection_model.connection.send(:type_map)
29+
connection_model.connection.raw_connection.prepare("#{statement} /*#{comment}*/") do |stmt|
30+
stmt.bind_params(bind_params)
31+
types = stmt.columns.zip(stmt.types).to_h { |c, t| [c, type_map.lookup(t)] }
32+
result = ActiveRecord::Result.new(stmt.columns, stmt.to_a, types)
33+
end
34+
else
35+
binds = bind_params.map { |v| ActiveRecord::Relation::QueryAttribute.new(nil, v, ActiveRecord::Type::Value.new) }
36+
result = connection_model.connection.select_all("#{statement} /*#{comment}*/", nil, binds)
37+
end
2938
end
3039

3140
columns = result.columns

0 commit comments

Comments
 (0)