From d9d524a2fedf3fcffeae3661bfffc44f463ee5ef Mon Sep 17 00:00:00 2001 From: Graham Knop Date: Fri, 7 Mar 2008 17:45:19 +0000 Subject: [PATCH] Use UTF8 for database connection when connecting to MySQL --- docs/changelog/7.x.x.txt | 1 + docs/upgrades/upgrade_7.5.5-7.5.6.pl | 9 ++++++++- lib/WebGUI/Cache/Database.pm | 6 +++++- lib/WebGUI/SQL.pm | 5 ++++- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 0793db796..521733039 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -1,4 +1,5 @@ 7.5.6 + - Use UTF8 for database connection when connecting to MySQL - Internationalized Calendar templates - fixed: exporting as HTML leaks sessions for inaccessible assets, - new YUI based date picker diff --git a/docs/upgrades/upgrade_7.5.5-7.5.6.pl b/docs/upgrades/upgrade_7.5.5-7.5.6.pl index 69baf9aa8..aabd0de40 100644 --- a/docs/upgrades/upgrade_7.5.5-7.5.6.pl +++ b/docs/upgrades/upgrade_7.5.5-7.5.6.pl @@ -22,11 +22,18 @@ my $quiet; # this line required my $session = start(); # this line required -# upgrade functions go here +convertCacheToBinary($session); finish($session); # this line required +sub convertCacheToBinary { + my $session = shift; + print "\tConverting database cache to binary data.\n" unless ($quiet); + $session->db->write('ALTER TABLE `cache` MODIFY COLUMN `content` mediumblob'); + $session->db->write('DELETE FROM `cache`'); +} + ##------------------------------------------------- #sub exampleFunction { # my $session = shift; diff --git a/lib/WebGUI/Cache/Database.pm b/lib/WebGUI/Cache/Database.pm index 852ae7ac1..52b68efc1 100644 --- a/lib/WebGUI/Cache/Database.pm +++ b/lib/WebGUI/Cache/Database.pm @@ -104,7 +104,11 @@ sub get { my $content = $data->[0]; return undef unless ($content); # Storable doesn't like non-reference arguments, so we wrap it in a scalar ref. - return ${thaw($content)}; + eval { + $content = thaw($content); + }; + return undef unless $content; + return $$content; } #------------------------------------------------------------------- diff --git a/lib/WebGUI/SQL.pm b/lib/WebGUI/SQL.pm index b20bfd8e9..1675b2ec2 100644 --- a/lib/WebGUI/SQL.pm +++ b/lib/WebGUI/SQL.pm @@ -319,7 +319,10 @@ sub connect { my $pass = shift; my $params = shift; - my $dbh = DBI->connect($dsn,$user,$pass,{RaiseError=>0,AutoCommit=>1 }); + my (undef, $driver) = DBI->parse_dsn($dsn); + my $dbh = DBI->connect($dsn,$user,$pass,{RaiseError => 0, AutoCommit => 1, + $driver eq 'mysql' ? (mysql_enable_utf8 => 1) : (), + }); unless (defined $dbh) { $session->errorHandler->error("Couldn't connect to database: $dsn");