From 33bef43e6b9be16e2addc60c0ae628c241798631 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Wed, 18 Feb 2015 12:38:39 +0100 Subject: [PATCH] =?utf8?q?DBUpgrade:=20Fehlermeldungen=20richtig=20in=20Pe?= =?utf8?q?rls=20Encoding=20=C3=BCbersetzen?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit DBD::Pg vor Version 2.16.1 hat das UTF-8-Flag bei Fehlermeldungen nicht gesetzt, auch wenn die Datenbankverbindung UTF-8 geflaggt war. Daher musste bei früheren Version von DBD::Pg kivitendo die Fehlermeldung selber ins richtige Encoding umwandeln. Das darf bei neueren Versionen natürlich nicht mehr gemacht werden. --- SL/DBUpgrade2/Base.pm | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/SL/DBUpgrade2/Base.pm b/SL/DBUpgrade2/Base.pm index 34afeae54..00df6d2e8 100644 --- a/SL/DBUpgrade2/Base.pm +++ b/SL/DBUpgrade2/Base.pm @@ -11,6 +11,7 @@ use File::Basename (); use File::Copy (); use File::Path (); use List::MoreUtils qw(uniq); +use version; use Rose::Object::MakeMethods::Generic ( scalar => [ qw(dbh myconfig) ], @@ -57,8 +58,14 @@ sub db_query { sub db_errstr { my ($self, $handle) = @_; + # DBD::Pg before 2.16.1 doesn't set the UTF-8 flag for error + # messages even if the connection has UTF-8 enabled. Therefore we + # have to convert it to Perl's internal encoding ourselves. See + # https://rt.cpan.org/Public/Bug/Display.html?id=53854 + my $error = $handle ? $handle->errstr : $self->dbh->errstr; + return $error if version->new("$DBD::Pg::VERSION")->numify >= version->new("2.16.1")->numify; return Encode::decode('utf-8', $error); } @@ -256,8 +263,10 @@ be used. =item C Returns the last database from C<$handle> error message encoded in -Perl's internal encoding. The PostgreSQL DBD leaves the UTF-8 flag off -for error messages even if the C attribute is set. +Perl's internal encoding. The PostgreSQL DBD before 2.16.1 leaves the +UTF-8 flag off for error messages even if the C +attribute is set. For older versions the error string is already +encoded correctly and is left unchanged. C<$handle> is optional and can be one of three things: -- 2.20.1