Yesterday I wrote about problems with reading utf8,
later I realized that the problems were actually in
the inserting, not the reading. Today I found a workaround.
The problem is caused by mysql, not by perl.
Maybe I'm doing something really stupit, but it seems
that my mysql-server doesn't accept utf8 as utf8. In the
most basic version, using a utf-8 file with sql commands:
mysql --default-character-set=utf8 test < test-insert.sql
my mysql server still interprets the utf8 strings in the file
as latin1 (and mangles all the non-latin1-charachters).
I tried inserting
SET CHARACTER SET utf8;
into the file, but that didn't help.
I had to change all occurences of literal utf8 strings in my SQL
statements, like so:
INSERT INTO sometable VALUES (....,CONVERT(_utf8'blabla' USING utf8), ...);
where 'blabla' is a string that might contain utf8.
the same for SELECT:
SELECT * FROM sometabel
WHERE somecolumn LIKE CONVERT(_utf8'%blabla%' USING utf8);
I now use this workaround through DBI. the data I get back is
not flagged as utf8, but it is correct utf8, so I can decode it
without a problem:
# to search for books with a title containging $char:
my $sql = qq{
SELECT * FROM buch WHERE Originaltitel LIKE
CONVERT(_utf8 '%$char%' USING utf8)
};
my $sth = $dbh->prepare($sql);
$sth->execute();
my (@r, $i);
while( @r = $sth->fetchrow_array() ) {
$_ = decode("utf8", $_) foreach @r;
print "<p>@r</p>";
}
It works. I'm glad. Thanks for the help.
Brigitte
p.s.
you can find the details at
http://perlwelt.horus.at/Beispiele/Magic/PerlUnicodeMysql/
--
Brigitte 'I never met a chocolate I didnt like' Jellinek
[EMAIL PROTECTED] http://www.horus.com/~bjelli/
http://perlwelt.horus.at http://www.perlmonks.org/index.pl?node=bjelli