sequel never returns utf-8, just ascii-8bit

末鹿安然 提交于 2020-01-21 01:34:06

问题


There is this mysql database I'm trying to connect to. DataMapper fetches everything nicely in UTF-8 but Sequel always returns strings in ASCII-8bit which produces errors with .to_json.

I have tried several things in order to get it to work.

Encoding.default_external = Encoding::UTF_8  
Encoding.default_internal = Encoding::UTF_8  
DB.run 'set names utf8'  
Sequel.mysql 'db', (...), :encoding => 'utf-8'  

I have gems: mysql (2.9.0) (tried without), mysql2 (0.3.11) and sequel (3.42.0)

The only thing that works is manually forcing the encoding on every string which is MUCH less than ideal.


回答1:


Try Sequel.mysql2 instead of Sequel.mysql. Sequel.mysql uses the old mysql driver instead of the new mysql2 driver, and I don't believe the mysql driver supports encodings.




回答2:


Encoding can be passed as do :

Sequel.connect("mysql2://user:pass@localhost/the_database?encoding=utf8")


来源:https://stackoverflow.com/questions/14070281/sequel-never-returns-utf-8-just-ascii-8bit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!