Subject: | mysql_enable_utf8 misses utf8 upgrading of non utf8 strings |
When using mysql_enable_utf8 DBD::mysql misses upgrading non utf8
strings. Instead it assumes that all data passed to DBD::mysql is valid
utf8 already. Non ASCII characters are simply removed from strings
passed to DBD::mysql.
Attached you find a patch against t/utf8.t (DBD-mysql-4.003 release)
which adds a correspondent regression test.
With this patch test #19 fails with the following message:
not ok 19 at line 185
got back 'umlauts: ' instead of 'umlauts: äüö'.
I'm using DBI 1.54 and DBD::mysql 4.003 compiled with MySQL 5.0.27
client libraries.
Subject: | DBD-mysql-4.003-missing-utf8-upgrade-test.patch.txt |
--- t/utf8.t 2007-03-21 11:59:04.954355876 +0100
+++ t/utf8.t.patched 2007-03-21 11:58:42.653080899 +0100
@@ -102,7 +102,7 @@
# Create a new table; In an ideal world, it'd be more sensible to
# make the whole database UTF8...
#
- $query = "CREATE TABLE $table (name VARCHAR(64) CHARACTER SET utf8, bincol BLOB, shape GEOMETRY)";
+ $query = "CREATE TABLE $table (name VARCHAR(64) CHARACTER SET utf8, bincol BLOB, shape GEOMETRY, test INTEGER)";
Test($state or $dbh->do($query))
or ErrMsgF("Cannot create table: Error %s.\n", $dbh->errstr);
@@ -113,24 +113,34 @@
my $utf8_str = "\x{0100}dam"; # "Adam" with a macron.
my $quoted_utf8_str = "'\x{0100}dam'";
-
+
my $blob = "\x{c4}\x{80}dam"; # same as utf8_str but not utf8 encoded
my $quoted_blob = "'\x{c4}\x{80}dam'";
+ my $umlaut_str = "umlauts: äüö";
+ my $quoted_umlaut_str = "'umlauts: äüö'";
+
Test( $state or ( $dbh->quote( $utf8_str ) eq $quoted_utf8_str ) )
or ErrMsg( "Failed to retain UTF-8 flag when quoting.\n" );
Test( $state or ( $dbh->quote( $blob ) eq $quoted_blob ) )
or ErrMsg( "UTF-8 flag was set when quoting.\n" );
+ Test( $state or ( $dbh->quote( $umlaut_str ) eq $quoted_umlaut_str ) )
+ or ErrMsg( "Failed to retain UTF-8 flag when quoting non-utf8 string.\n" );
+
Test( $state or ( $dbh->{ mysql_enable_utf8 } ) )
or ErrMsg( "mysql_enable_utf8 didn't survive connect()\n" );
- $query = qq{INSERT INTO $table (name, bincol, shape) VALUES (?,?, GeomFromText('Point(132865 501937)'))};
+ $query = qq{INSERT INTO $table (name, bincol, shape, test) VALUES (?,?, GeomFromText('Point(132865 501937)'),1)};
Test( $state or $dbh->do( $query, {}, $utf8_str,$blob ) )
or ErrMsgF( "INSERT failed: query $query, error %s.\n", $dbh->errstr );
- $query = "SELECT name,bincol,asbinary(shape) FROM $table LIMIT 1";
+ $query = qq{INSERT INTO $table (name,test) values (?,2)};
+ Test( $state or $dbh->do( $query, {}, $umlaut_str ) )
+ or ErrMsgF( "INSERT failed: query $query, error %s.\n", $dbh->errstr );
+
+ $query = "SELECT name,bincol,asbinary(shape) FROM $table WHERE test=1 LIMIT 1";
Test( $state or ($sth = $dbh->prepare( $query ) ) )
or ErrMsgF( "prepare failed: query $query, error %s.\n", $dbh->errstr );
@@ -158,6 +168,22 @@
Test( $state or ($ref->[1] eq $blob) )
or ErrMsgF( "got back '$ref->[1]' instead of '$blob'.\n" );
+ Test( $state or $sth->finish )
+ or ErrMsgF( "Cannot finish: %s.\n", $sth->errstr );
+
+ # test if non-utf8 tagged data was inserted correctly
+ $query = "SELECT name FROM $table WHERE test=2 LIMIT 1";
+ Test( $state or ($sth = $dbh->prepare( $query ) ) )
+ or ErrMsgF( "prepare failed: query $query, error %s.\n", $dbh->errstr );
+
+ Test($state or $sth->execute)
+ or ErrMsgF( "execute failed: query $query, error %s.\n", $dbh->errstr );
+
+ Test( $state or defined( $ref = $sth->fetchrow_arrayref ) )
+ or ErrMsgF( "fetch failed: query $query, error %s.\n", $sth->errstr );
+
+ Test( $state or ($ref->[0] eq $umlaut_str) )
+ or ErrMsgF( "got back '$ref->[0]' instead of '$umlaut_str'.\n" );
Test( $state or $sth->finish )
or ErrMsgF( "Cannot finish: %s.\n", $sth->errstr );