|Subject:||Be more clear about the UTF8 flag|
It took me a while to figure that the UTF8 flag always has to be set when writing to a database that supports unicode characters. The text in DBIx::Class::Manual::Cookbook says that "it is better to avoid encoding/decoding data and to use your database's own unicode capabilities" but I was mislead by that statement. My program gets text from another source. The text is properly decoded to characters but internally not represented in UTF-8. If this text is written to a file or the console with proper encoding settings everything is fine. When writing to a properly configured MySQL database and mysql_enable_utf8 set, I get an error from find_or_create(). Only after reading DBIx::Class::UTF8Columns I realized that there's a long standing bug in DBIx::Class and that I have to force Perl to represent the text internally in UTF-8 as create() will treat the text as a byte sequence. I now call decode_utf8(encode_utf8($text)) in order to ensure that the UTF-8 flag is set. The cookbook should make it more clear that the UTF8 flag needs to be set. At first I didn't read DBIx::Class::UTF8Columns as the cookbook says that it should not be "used with a database that does correctly handle unicode" but in order to understand the problem you have to know about this bug.