Skip to content

Commit

Permalink
Move MYSQL_ENABLE_UTF8 to a connection-level attribute
Browse files Browse the repository at this point in the history
When MYSQL_ENABLE_UTF8 is set, it currently does not provide the
mysql_enable_utf8 parameter to the DBI->connect call; instead it's
part of the DBI handle attributes that get set on an already-created
handle.

From the docs for DBD::mysql, mysql_enable_utf8 needs to be set on
connect, otherwise there are additional steps one needs to take to get
the results returned in UTF8 (primarily issuing a $dbh->do("SET NAMES
utf8") on the opened handle).

With this change, when the catalog.cfg defines MYSQL_ENABLE_UTF8, the
mysql_enable_utf8 => 1 attribute will be included in the hash of
options returned by Vend::Table::DBI::find_dsn.  This will not occur
unless said DatabaseDefault/Database attribute is defined.

This corrects a bug when using MySQL with MV_UTF8 mode, as with the
old behavior the UTF8 flag would be set on the values returned from
the database, but they would not have been transferred in UTF8, but
instead with the server's default character set (likely latin1).  The
normal way to get around this issue when setting the $dbh attribute
manually is to issue a $dbh->do("SET NAMES utf8"), which has the
effect of setting the client's connection and results character sets
to UTF8.

This has the possibility of introducing some changes in application
behavior, but since MYSQL_ENABLE_UTF8 is generally turned on in
conjunction with MV_UTF8 mode, this is not judged to be a big risk.
If existing user code was already working around this bug by issuing
its own $dbh->do("SET NAMES utf8"), this will continue to work,
essentially becoming a no-op.
  • Loading branch information
David Christensen committed Apr 16, 2010
1 parent 3766daf commit d591b9a
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions lib/Vend/Table/DBI.pm
Expand Up @@ -56,6 +56,7 @@ my %Cattr = ( qw(
RAISEERROR RaiseError
PRINTERROR PrintError
AUTOCOMMIT AutoCommit
MYSQL_ENABLE_UTF8 mysql_enable_utf8
) );
my @Cattr = keys %Cattr;

Expand Down

0 comments on commit d591b9a

Please sign in to comment.