Hi,

Having looked through the list archives a bit, I see there has been lots of discussion over what to do with UTF-8 data, but I can't find anything that really helps me out now.

I'm running Perl 5.8.0 with MySQL 3.23.56 (via DBD-mysql). Since (I think) there is no native UTF-8 support in MySQL below 4.1.x, my plan was to simply store the bytes of each UTF-8 character in the database (either by explicitly converting Perl's UTF-8 strings to sequences of octets using Encode::encode_utf8(), or else just letting that happen of its own accord as it seems to do :-s), and then convert such octet sequences back to UTF-8 strings when retrieving data from the database using Encode::decode_utf8().

As long as I store *all* my data in this way, those conversions should always succeed. (encode_utf8() never fails anyway, and decode_utf8() will always work here because I'm always feeding it "valid" data.)

The problem is: How do I trap all input/output to/from DBI to do these conversions?

I can easily do it "manually":

$dbh->do('INSERT INTO foo (bar) VALUES (?)', undef, Encode::encode_utf8($input_utf8str));
...
my @octets_row = $dbh->selectrow_array('SELECT bar FROM foo');
my $output_utf8str2 = Encode::decode_utf8($octets_row[0]);


but that's way too tedious in practice. I want to have those conversions done for me automatically, perhaps by having specified some appropriate encode/decode callbacks for certain hooks. Do any such hooks exist?

If, as I suspect, there are not, then what is the currently recommended solution here?

Would it be at all easy to add such hooks, or some other means of specifying that I want these conversions done, to DBI as a stop-gap solution?

Thanks,
- Steve



Reply via email to