-
Notifications
You must be signed in to change notification settings - Fork 563
Description
Hi,
When using your excellent sqlserver adapter with ruby 1.9.1, uploading a binary (PNG in my case) will fail in the binary_to_string method with the following error:
ArgumentError (invalid byte sequence in UTF-8):
/Users/jeroen/.bundle/ruby/1.9.1/gems/activerecord-sqlserver-adapter-2.3.4/lib/active_record/connection_adapters/sqlserver_adapter.rb:61:in binary_to_string' /Users/jeroen/.bundle/ruby/1.9.1/gems/activerecord-sqlserver-adapter-2.3.4/lib/active_record/connection_adapters/sqlserver_adapter.rb:70:intype_cast'
I looked at the source of activerecord and found that the sqlite adapter has an apparent fix/workaround for this:
def binary_to_string(value)
value = value.dup.force_encoding(Encoding::BINARY) if value.respond_to?(:force_encoding)
# etc.
Adding the above line to the sqlserver adapter fixes the problem for me.
The sqlite adapter also uses this for string_to_binary:
def string_to_binary(value)
value = value.dup.force_encoding(Encoding::BINARY) if value.respond_to?(:force_encoding)
# etc.
Could you incorporate these changes in your adapter and release a new version?
Thanks,
Jeroen