Re: Database character sets

[prev] [thread] [next] [Date index for 2005/02/22]

From: Dan Sully
Subject: Re: Database character sets
Date: 18:04 on 22 Feb 2005
* Tom Insam shaped the electrons to say...

>I'd like to use Class::DBI and a database to store character sequences, 
>as opposed to bytes, specifically I'd like things in the database to be 
>encoded as utf-8 byte sequences everywhere. Although mysql4.1, which is 
>my current development target, claims to support character sets on 
>tables, it doesn't look like DBD::mysql knows how to deal with this. 
>Anyway, it may be that we're moving DB servers, and I don't want to 
>have to require that the new server knows about them.
>
>Is this a solved problem yet? I'm hoping that it _must_ be, but I can't 
>find anything in the archives of this list or the wiki about it.

Perrin is right, in that it's more of a DBI issue, however, I've had to deal
with this as well. Assuming all of your data is flagged / encoded as UTF-8 on
the way into the database:

# overload Class::DBI's get, because DBI doesn't support auto-flagging of utf8
# data retrieved from the db, we need to do it ourselves.
sub get {
        my $self = shift;
        my $attr = shift;

        my $data = $self->SUPER::get($attr, @_);

        if ($] > 5.007) {
                Encode::_utf8_on($data);
        }

        return $data;
}

-D
        -- 
        <noah> I used to be indecisive, but now I'm not sure.

Database character sets
Tom Insam 15:18 on 22 Feb 2005

Re: Database character sets
Perrin Harkins 17:38 on 22 Feb 2005

Re: Database character sets
Tom Insam 18:05 on 22 Feb 2005

Re: Database character sets
Drew Wilson 18:23 on 22 Feb 2005

Re: Database character sets
Tom Insam 19:09 on 22 Feb 2005

Re: Database character sets
Dan Sully 18:04 on 22 Feb 2005

Re: Database character sets
Tom Insam 19:11 on 22 Feb 2005

Re: Database character sets
Dan Sully 19:15 on 22 Feb 2005

Generated at 00:32 on 04 Mar 2005 by mariachi v0.52