blessing db data as utf8

blessing db data as utf8

am 09.06.2004 15:01:09 von Gaal Yahas

Hello,

My data is stored on a mysql 4.0.20 server, in utf8. The database doesn't
know it is utf8; as far as I could tell this version doesn't have full
support for setting unicode charsets yet (please correct me if I'm wrong).

The problem is that when I fetch the data with DBD::mysql, perl doesn't
mark it as utf8, resulting in garbage data and forcing me to use workarounds
such as calling Encode::_utf8_on on my strings.

I'm unsure about the best place to do this, but it turns out that DBD::Pg
has addressed the same problem for Postgres as a global perl-dbh switch.

What do the maintainers of DBD::mysql say? Should the same style of fix
be added to DBD::mysql? I'm willing to work on a patch if nobody else steps
forward.

Gaal

PS: The forwarded message below is from the Class::DBI-talk mailing list.

----- Forwarded message from Dominic Mitchell -----

Message-ID: <40C6FBC2.8070901@semantico.com>
Date: Wed, 09 Jun 2004 13:00:02 +0100
From: Dominic Mitchell

Gaal Yahas wrote:
>On Wed, Jun 09, 2004 at 01:23:49PM +0200, Andreas Fromm wrote:
>
>>>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 :)
>>>
>>
>>What abaut PostgerSQL where you tell the server at database-creation how
>>to encode the Data? When I create a db with unicode encoding, it
>>_should_ know abaut encoding, doesn't it?
>
>I don't have pg to test this with, but it seems you are more lucky:
>and that in that database's case, perhaps the right place to fix this
>would be DBD::Pg--or maybe Class::DBI::Pg?

DBD::Pg can already support utf8. I patched it last year, and versions
1.22 onwards support a $dbh->{pg_enable_utf8} attribute. It's a bit
kludgy (ignores database encoding) and I don't know direction Unicode
support in DBI is going in generally, so it may change in the future.
But this works now.

-Dom

--
| Semantico: creators of major online resources |
| URL: http://www.semantico.com/ |
| Tel: +44 (1273) 722222 / Fax: +44 (1273) 723232 |
| Address: 33 Bond St., Brighton, Sussex, BN1 1RD, UK. |

----- End forwarded message -----

--
Gaal Yahas
http://gaal.livejournal.com/

--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org