Re: blessing db data as utf8

[prev] [thread] [next] [Date index for 2004/06/09]

From: Gaal Yahas
Subject: Re: blessing db data as utf8
Date: 11:12 on 09 Jun 2004
On Wed, Jun 09, 2004 at 06:23:01AM +0100, Tony Bowden wrote:
> On Wed, Jun 09, 2004 at 12:07:39AM +0300, Gaal Yahas wrote:
> > Is there a CDBI way to implement the workaround described here for straight DBI?
> >      http://perlmonks.thepen.com/314423.html
> > Briefly, the problem is getting perl to think of a string as utf8
> > "even when it IS".
> > What I'm looking for is a way for Class::DBI to perform the autoconversion
> > for me transparently.
> 
> I don't really understand the utf8 issues well enough to know whether
> this conversion needs to happen at a certain point, but if it's just a
> matter of calling Encode::_utf8_on on each value fetched from the
> database, you can probably do somehing in sth_to_objects(), or possibly
> construct(), or even _init() if there's no problem in doing it on data
> you're passing to create() yourself.
 
Regarding creation, it's safe to call Encode::_utf8_on multiple times
on a string that is utf8, though of course it slows things down and
it's reasonable to require the application to hand over utf8 strings
to the database. (BTW, there's a pack/unpack hack to do the same thing
as Encode::_utf8_on but without the overhead.)

> It may be better doing it in DBIx::ContextualFetch though, or even in
> DBI itself...

The problem is that the database doesn't know better: as far as it is
concerned, the data is (say) latin1. This is true at least for mysql 4.0.20
which I have been using. This means that the metadata about encoding type
of a table or a column can't come from the database, even though ideally
it should. I don't know DBIx::ContextualFetch to say, but DBI seems at the
moment to be too low-level for this kind of knowledge.

That said, *my* data is all utf8, so I don't mind a global switch :)

        -- 
        Gaal Yahas <gaal@xxxxxx.xxx>
http://gaal.livejournal.com/

(message missing)

blessing db data as utf8
Gaal Yahas 21:07 on 08 Jun 2004

Re: blessing db data as utf8
Tony Bowden 05:23 on 09 Jun 2004

Re: blessing db data as utf8
Gaal Yahas 11:12 on 09 Jun 2004

Re: blessing db data as utf8
Gaal Yahas 11:44 on 09 Jun 2004

Re: blessing db data as utf8
Gaal Yahas 20:28 on 09 Jun 2004

Re: blessing db data as utf8
Tim Bunce 08:51 on 10 Jun 2004

Re: blessing db data as utf8
Gaal Yahas 09:18 on 10 Jun 2004

Re: blessing db data as utf8
Tim Bunce 18:01 on 10 Jun 2004

Re: blessing db data as utf8
Gaal Yahas 18:49 on 10 Jun 2004

Generated at 11:35 on 01 Dec 2004 by mariachi v0.52