Closed D-system closed 8 months ago
Another solution less dirty that can lives as a monkey patch for now and unblock the situation:
# config/initializers/blazer_utf8.rb
module Blazer
class Result
def columns
@columns.map { _1.dup.force_encoding("utf-8") }
end
end
end
Hi @D-system, thanks for reporting. It looks like it only causes an error when the query generates a chart:
SELECT 'a' AS "え", 1 AS "あ"; /* error */
SELECT 'a' AS "え", 'b' AS "あ"; /* no error */
but haven't identified the cause.
It looks like that's just the behavior of Action View, as this generates the same error:
<%= "え" %>
<%= "え".force_encoding(Encoding::US_ASCII) %>
Fixed in the commit above. Thanks again!
Thanks @ankane for the rapid fix 🙇♂️
Hi,
Rails added a new official mysql adapter called Trilogy which is pure Ruby (no native mysql lib needed). Trilogy is inside Rails 7.1. For previous versions of Rails, there's a gem https://rubygems.org/gems/activerecord-trilogy-adapter. The mysql2 adapter does not have that issue.
Blazer: github master branch (ccad9055323786eb37dd976abac786f51f99fa94) Rails: 6.1.7.6 Ruby 3.2.2 Database: mysql with Trilogy adapter Error:
ActionView::Template::Error (incompatible character encodings: UTF-8 and US-ASCII)
The issue is with non-ascii (Japanese characters in UTF-8 in that case). Strangely enough is does work with a single column retrieve. Multiple columns with 1 column or all columns in UTF-8 does not work.
Looking at the code, a dirty fix would be to change https://github.com/ankane/blazer/blob/ccad9055323786eb37dd976abac786f51f99fa94/app/controllers/blazer/queries_controller.rb#L156 with:
Line 118 probably need that change too.
Thanks!
Bracetrace
Started POST "/blazer/queries/run" for ::1 at 2024-01-04 19:09:44 +0900 EcmsUser Load (0.6ms) SELECT `ecms_users`.* FROM `ecms_users` WHERE `ecms_users`.`deleted_at` IS NULL AND `ecms_users`.`id` = 1 ORDER BY `ecms_users`.`id` ASC LIMIT 1 Processing by Blazer::QueriesController#run as HTML Parameters: {"statement"=>"select a.jan_code, a.id as \"あ\"\r\nfrom jans a\r\nLIMIT 2\r\n;\r\n\r\n", "data_source"=>"main", "run_id"=>"ec57aeab-29a4-4aff-8a41-e83ab0a4810c"} TRANSACTION (0.3ms) BEGIN Blazer::Audit Create (1.9ms) INSERT INTO `blazer_audits` (`user_id`, `statement`, `data_source`, `created_at`) VALUES (1, 'select a.jan_code, a.id as \"あ\"\r\nfrom jans a\r\nLIMIT 2\r\n;\r\n\r\n', 'main', '2024-01-04 19:09:44') TRANSACTION (0.5ms) COMMIT TRANSACTION (0.2ms) BEGIN (1.3ms) SET max_execution_time = 30000 (0.3ms) select a.jan_code, a.id as "あ" from jans a LIMIT 2 ; /*blazer,user_id:1,user_name: Nakumura,run_id:ec57aeab-29a4-4aff-8a41-e83ab0a4810c*/ TRANSACTION (0.2ms) ROLLBACK Rendering /Users/thomas/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/bundler/gems/blazer-ccad90553237/app/views/blazer/queries/run.html.erb Rendered /Users/thomas/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/bundler/gems/blazer-ccad90553237/app/views/blazer/queries/_caching.html.erb (Duration: 0.0ms | Allocations: 9) hash_method_missing to_ary /Users/thomas/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/chartkick-5.0.5/lib/chartkick/helper.rb:91:in `%' hash_method_missing to_ary /Users/thomas/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/chartkick-5.0.5/lib/chartkick/helper.rb:103:in `%' Rendered /Users/thomas/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/bundler/gems/blazer-ccad90553237/app/views/blazer/queries/run.html.erb (Duration: 0.7ms | Allocations: 748) Completed 500 Internal Server Error in 15ms (ActiveRecord: 4.7ms | SQL Queries: 7 (0 cached) | Allocations: 8685) ActionView::Template::Error (incompatible character encodings: UTF-8 and US-ASCII): 139: <% type = @column_types[i] %> 140: