From b2b6db0dfec7022ec3e95c9ec5d535f3fde793a4 Mon Sep 17 00:00:00 2001 From: Thomas Brennetot Date: Tue, 30 Jan 2024 09:46:06 +0900 Subject: [PATCH] Fix encoding error on columns when using Trilogy It happens when 2 columns are selected, one of which is a JSON type with non-ASCII characteres (eg: Japanese). Blazer will try render the entire template in UTF-8 and that field in ASCII-8BIT. Error: ``` ActionView::Template::Error incompatible character encodings: UTF-8 and ASCII-8BIT ``` Tested on MySQL 5.7. --- lib/blazer/adapters/sql_adapter.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/blazer/adapters/sql_adapter.rb b/lib/blazer/adapters/sql_adapter.rb index 154158b86..9ebd3b2af 100644 --- a/lib/blazer/adapters/sql_adapter.rb +++ b/lib/blazer/adapters/sql_adapter.rb @@ -36,6 +36,11 @@ def run_statement(statement, comment, bind_params = []) # fix for non-ASCII column names and charts if adapter_name == "Trilogy" columns.map! { |k| k.dup.force_encoding(Encoding::UTF_8) } + rows.each do |row| + row.each do |column| + column.force_encoding(Encoding::UTF_8) if column.is_a?(String) + end + end end rescue => e error = e.message.sub(/.+ERROR: /, "")