Skip to content

Business intelligence made simple

Fixed types for SQLite - resolves #494 and resolves #495

Andrew Kaneaae3f543780c
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7533b95a..79922dd3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,6 @@
## 3.1.1 (unreleased)
+- Fixes types for SQLite
- Fixed table preview and schema page for SQLite
## 3.1.0 (2024-10-14)
diff --git a/lib/blazer/adapters/sql_adapter.rb b/lib/blazer/adapters/sql_adapter.rb
index 16ec6c47..46064154 100644
--- a/lib/blazer/adapters/sql_adapter.rb
+++ b/lib/blazer/adapters/sql_adapter.rb
@@ -24,8 +24,17 @@ module Blazer
result = nil
in_transaction do
set_timeout(data_source.timeout) if data_source.timeout
- binds = bind_params.map { |v| ActiveRecord::Relation::QueryAttribute.new(nil, v, ActiveRecord::Type::Value.new) }
- result = connection_model.connection.select_all("#{statement} /*#{comment}*/", nil, binds)
+ if sqlite?
+ type_map = connection_model.connection.send(:type_map)
+ connection_model.connection.raw_connection.prepare("#{statement} /*#{comment}*/") do |stmt|
+ stmt.bind_params(bind_params)
+ types = stmt.columns.zip(stmt.types).to_h { |c, t| [c, type_map.lookup(t)] }
+ result = ActiveRecord::Result.new(stmt.columns, stmt.to_a, types)
+ end
+ else
+ binds = bind_params.map { |v| ActiveRecord::Relation::QueryAttribute.new(nil, v, ActiveRecord::Type::Value.new) }
+ result = connection_model.connection.select_all("#{statement} /*#{comment}*/", nil, binds)
+ end
end
columns = result.columns