On Apr 25, 4:51 pm, "pYuri.fy" <[email protected]> wrote: > I'm trying to save some Japanese data encoded in UTF-8 into a Sqlite3 > database. When I retrieve a record, > I find that the data has been re-encoded to ASCII 8-BIT. This wouldn't > be a problem but when I update > a field with new UTF-8 data and try to save it, Ruby raises an error: > > Encoding::CompatibilityError: incompatible character encodings: UTF-8 > and ASCII-8BIT > from /usr/local/lib/ruby/gems/1.9.1/gems/sequel-2.12.0/lib/sequel/ > dataset/sql.rb:754:in `join' > from /usr/local/lib/ruby/gems/1.9.1/gems/sequel-2.12.0/lib/sequel/ > dataset/sql.rb:754:in `update_sql' > from /usr/local/lib/ruby/gems/1.9.1/gems/sequel-2.12.0/lib/sequel/ > dataset.rb:255:in `update' > from /usr/local/lib/ruby/gems/1.9.1/gems/sequel-2.12.0/lib/sequel/ > model/base.rb:814:in `_save' > from /usr/local/lib/ruby/gems/1.9.1/gems/sequel-2.12.0/lib/sequel/ > model/base.rb:687:in `block in save' > from /usr/local/lib/ruby/gems/1.9.1/gems/sequel-2.12.0/lib/sequel/ > adapters/sqlite.rb:99:in `block (2 levels) in transaction' > from /usr/local/lib/ruby/gems/1.9.1/gems/sqlite3-ruby-1.2.4/lib/ > sqlite3/database.rb:564:in `transaction' > from /usr/local/lib/ruby/gems/1.9.1/gems/sequel-2.12.0/lib/sequel/ > adapters/sqlite.rb:99:in `block in transaction' > from /usr/local/lib/ruby/gems/1.9.1/gems/sequel-2.12.0/lib/sequel/ > connection_pool.rb:110:in `hold' > from /usr/local/lib/ruby/gems/1.9.1/gems/sequel-2.12.0/lib/sequel/ > database.rb:472:in `synchronize' > from /usr/local/lib/ruby/gems/1.9.1/gems/sequel-2.12.0/lib/sequel/ > adapters/sqlite.rb:94:in `transaction' > from /usr/local/lib/ruby/gems/1.9.1/gems/sequel-2.12.0/lib/sequel/ > model/base.rb:687:in `save' > > Is there a way to tell Sequel to use a specific encoding when storing > a record? Or a option to set which encoding > to use when creating the table?
I'm not sure if SQLite respects character encodings, but that's not the issue. It looks like the issue is joining an array of strings inside update_sql. I'm guessing it thinks the string that joins the elements of the array isn't the same as the encoding of one of the strings in the array. I'm guessing the joiner is considered ASCII-8BIT and at least one of the strings in the array is UTF8. I don't know if that is fixable easily without forcing the encoding before the call to update. Personally, I think letting each string have its own encoding is a terrible mistake, leading to problems like the one you are having. IMO, Ruby should have either stayed the way it was (where all strings are just arrays of bytes), or gone the python 3.0 route where you have byte strings as one type and all character strings are unicode. I know unicode has its problems, but it's better than having to deal with this type of problem. The string encoding issue is the main reason that I don't use 1.9.1 in production, FWIW. Jeremy --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sequel-talk" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/sequel-talk?hl=en -~----------~----~----~----~------~----~------~--~---
