On Thursday, March 29, 2018 at 8:03:43 AM UTC-7, Satyanarayana Gandham 
wrote:
>
> Hi Jeremy,
>
> Thanks for the reply. Unfortunately, it is not working when I add 
> "encoding=binary".
>
> 2.3.1 :001 > require 'sequel'
>  => true 
> 2.3.1 :002 > require 'json'
>  => true 
> 2.3.1 :003 > DB = Sequel.connect(
> "mysql2://username:password@localhost/db?socket=/var/run/mysql-default/mysqld.sock&encoding=binary"
> )
>  => #<Sequel::Mysql2::Database: 
> "mysql2://username:password@localhost/db?socket=/var/run/mysql-default/mysqld.sock&encoding=binary">
>  
>
> 2.3.1 :004 > class Clinic < Sequel::Model; end
>  => nil 
> 2.3.1 :005 > Clinic.first
>  => #<Clinic @values={:name=>"St. 
> Michael\xC3\xA2\xE2\x82\xAC\xE2\x84\xA2s Hopsital"}> 
> 2.3.1 :006 > Clinic.first.values.to_json
> Encoding::UndefinedConversionError: "\xC3" from ASCII-8BIT to UTF-8
>   from (irb):6:in `encode'
>   from (irb):6:in `to_json'
>   from (irb):6
>   from /usr/local/rvm/rubies/ruby-2.3.1/bin/irb:11:in `<main>'
> 2.3.1 :007 > Clinic.plugin(:force_encoding, 'UTF-8')
>  => "UTF-8" 
> 2.3.1 :008 > Clinic.first
>  => #<Clinic @values={:name=>"St. Michael’s Hopsital"}> 
> 2.3.1 :009 > Clinic.first.values.to_json
>  => "{\"name\":\"St. Michael’s Hopsital\"}" 
>
>
>
Weird, the encoding=binary option appeared to solve the issue on my end, 
but it could be my MySQL database is configured differently.  In any case, 
this doesn't appear to be a Sequel issue, it appears to be an issue with 
the mysql2 driver.  Please contact the mysql2 developers and get feedback 
from them on how to get mysql2 to work correctly.  Once you've determined 
how to use mysql2 directly to solve the problem, if you still have issues 
using Sequel's mysql2 adapter, then you can post back here and I should be 
able to help.

Thanks,
Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to