On Tuesday, March 27, 2018 at 3:23:28 AM UTC-7, Satyanarayana Gandham wrote:
>
> Hi Jeremy,
>
> Thanks for the reply.
>
> Below is the code to reproduce.
>
> In irb, The data is loaded in this way using mysql gem.
> 2.3.1 :001 > require 'sequel'
> => true
> 2.3.1 :002 > require 'json'
> => true
> 2.3.1 :003 >
> 2.3.1 :004 > DB = Sequel.connect(
> "mysql://username:password@localhost/db?socket=/var/run/mysql-default/mysqld.sock"
> )
> => #<Sequel::MySQL::Database:
> "mysql://username:password@localhost/db?socket=/var/run/mysql-default/mysqld.sock">
>
>
> 2.3.1 :005 >
> 2.3.1 :006 > DB.drop_table?(:clinics)
> => [:clinics]
> 2.3.1 :007 > DB.create_table(:clinics) { String :name }
> => nil
> 2.3.1 :008 > class Clinic < Sequel::Model; end
> => nil
> 2.3.1 :009 >
> 2.3.1 :010 > Clinic.create(name: "St. Michael’s Hopsital")
> => #<Clinic @values={:name=>"St. Michael’s Hopsital"}>
> 2.3.1 :011 >
> 2.3.1 :012 > Clinic.first
> => #<Clinic @values={:name=>"St. Michael\xE2\x80\x99s Hopsital"}>
> 2.3.1 :013 > Clinic.first.values.to_json
> Encoding::UndefinedConversionError: "\xE2" from ASCII-8BIT to UTF-8
> from (irb):13:in `encode'
> from (irb):13:in `to_json'
> from (irb):13
> from /usr/local/rvm/rubies/ruby-2.3.1/bin/irb:11:in `<main>'
> 2.3.1 :014 >
> 2.3.1 :015 > Clinic.plugin(:force_encoding, 'UTF-8')
> => "UTF-8"
> 2.3.1 :016 >
> 2.3.1 :017 > Clinic.first
> => #<Clinic @values={:name=>"St. Michael’s Hopsital"}>
> 2.3.1 :018 > Clinic.first.values.to_json
> => "{\"name\":\"St. Michael’s Hopsital\"}"
>
>
>
> In irb, Using mysql2 gem, I am getting the following:
> 2.3.1 :001 > require 'sequel'
> => true
> 2.3.1 :002 > require 'json'
> => true
> 2.3.1 :003 >
> 2.3.1 :004 > DB = Sequel.connect(
> "mysql2://username:password@localhost/db?socket=/var/run/mysql-default/mysqld.sock"
> )
>
This should get you similar behavior on mysql2 as you had on mysql:
DB =
Sequel.connect("mysql2://username:password@localhost/db?socket=/var/run/mysql-default/mysqld.sock&encoding=binary")
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.