rowland / fb

Firebird Extension Library for Ruby
64 stars 35 forks source link

Strings are always ASCII-8BIT... #18

Closed ramsees closed 12 years ago

ramsees commented 12 years ago

The adapter ignores the default charset, if I use utf8 It should return UTF-8 encoded strings, but It always returns ASCII-8BIT strings.

This is a problem concatenating strings in Ruby, becase UTF-8 and ASCII-8BIT are not compatible, for example this causes an error if the string containts any of the characters á é í ó ú.

"Hello" + data["my_string"]

I need to do this

"Hello" + data["my_string"].force_encoding("UTF-8")

Doing this is tedious, specially in Sinatra applications.

rowland commented 12 years ago

I didn't tackle character set encodings, because I thought I would need to transliterate based on database and column charsets, but it shouldn't be hard to call force_encoding on all returned strings with the encoding specified at the connection level. Would that be acceptable?

If your data is not valid according to the specified encoding, it would fail later operations like regular expressions.

On Feb 13, 2012, at 2:43 PM, ramsees wrote:

The adapter ignores the default charset, if I use utf8 It should return UTF-8 encoded strings, but It always returns ASCII-8BIT strings.

This is a problem concatenating strings in Ruby, becase UTF-8 and ASCII-8BIT are not compatible, for example this causes an error if the string containts any of the characters á é í ó ú.

"Hello" + data["my_string"]

I need to do this

"Hello" + data["my_string"].force_encoding("UTF-8")

Doing this is tedious, specially in Sinatra applications.


Reply to this email directly or view it on GitHub: https://github.com/rowland/fb/issues/18

ramsees commented 12 years ago

Thanks for the answer, Yeah, it is acceptable and it is something I did with my local gem (modifying fb.c).