On Sep 11, 5:38 pm, cult hero <[email protected]> wrote:
> I guess I just want to ask generally... what do I do?
>
> In my connection YAML file I have "encoding: UTF-8" set (PostgreSQL
> 8.4, by the way) but... I'm still having issues when I get information
> back.
>
> So, for model "Model" and field "field", here's what I am running into
> from the console.
>
> >> __ENCODING__.name
> => "UTF-8"
> >> model = Model.new
>
> => #<Model @values={}>>> model.field = "über"
> => "über"
> >> model.field.encoding.name
> => "UTF-8"
> >> model.save
>
> => #<Model @values={:id=>1, field=>"über"}>>> model = Model[1]
>
> => #<Model @values={:id=>1, field=>"\xC3\xBCber"}>>> model.field
> => "\xC3\xBCber"
> >> model.field.encoding.name
> => "ASCII-8BIT"
> >> model.field.force_encoding("UTF-8")
>
> => "über"
>
> Is there some way to tell my model to use some kind of client encoding
> or something? Clearly everything is getting written correctly because
> if I jump through enough hoops the data ends up as intended and when I
> look at it in an outside client, the data is "über" as expected or is
> there some single place I can override behavior so it'll return the
> "force_encoding" version on all my models?
>
> (I can tell this is going to be trouble around to board too since some
> HTTP stuff I'm sending is getting garbled and being weird too.)
>
> And this isn't a sequel specific question, but it might solve the
> problem: Is there some way to say, "Hey, look, everything from the
> source files to the database to the HTTP communications in this
> environment are going to be in UTF-8. Just force all the strings to
> that."

I don't think there is any ruby way to do that.  For Sequel::Model
there's really only two issues: model objects loaded from the
database, and everything else.   To fix data coming from the database,
a model plugin that overrides load in ClassMethods, call super, and
the iterate over the values forcing the encoding of all of the strings
should work.  For everything else, an extension that overrode
typecast_value_string for the database to force encoding should do the
job (assuming you have typecasting turned on).

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
-~----------~----~----~----~------~----~------~--~---

Reply via email to