kubo / ruby-oci8

Ruby-oci8 - Oracle interface for ruby
Other
169 stars 75 forks source link

Force encoding via `force_string_encoding` property #250

Closed llhhaa closed 8 months ago

llhhaa commented 1 year ago

When creating string bindings, use String#force_encoding, instead of String#encode, via the force_string_encoding property.

My intent here is to allow the writing of UTF-8 strings to legacy encoding types without monkey-patching ruby-oci8.

Backstory: we have a large, old Oracle database with ASCII encoding. It's huge and Oracle is deprecated for us, so we're not taking on the maintenance to move these to UTF-8. What we've done instead is patch ruby-oci8 so we can persist our escaped UTF-8 strings in ASCII, then use ActiveSupport::Multibyte#tidy_bytes to convert them back to UTF-8 on read.

I know this is probably an uncommon need at this point, so if there isn't sufficient utility in such a flag or there are other reasons not to add such a feature, let me know.