Subject: | Warnings and errors don't have the UTF-8 flag turned on |
Date: | Fri, 20 Feb 2015 12:18:26 +0100 |
To: | bug-DBD-Pg [...] rt.cpan.org |
From: | Moritz Bunkus <moritz [...] bunkus.org> |
Hey,
warnings and errors issued by DBD::Pg v3.5.0 don't have their UTF-8 flag
turned on even if the connection itself has UTF-8 turned on. With the
following test case the unmodified warnings and errors don't appear
correct on the screen (this is with a PostgreSQL DB whose encoding is
de_DE.UTF-8). The wrongly encoded messages look something like this:
Warning not decoded: DBD::Pg::db do failed: FEHLER: Relation âqweqweqweâ existiert nicht
LINE 1: SELECT asdasd FROM qweqweqwe
^ at ./perl1.pl line 49.
instead of
Warning decoded: DBD::Pg::db do failed: FEHLER: Relation „qweqweqwe“ existiert nicht
LINE 1: SELECT asdasd FROM qweqweqwe
^ at ./perl1.pl line 49.
(The meaning is: relation qweqweqwe does not exist)
UTF-8 does work on the connection in general, that's what the
selectrow_array() line aims to prove. Decoding the warnings and errors
does work, but there's no way to distinguish between DBD::Pg's
warnings/errors and those produced by other parts of the program.
Example program:
use utf8;
use strict;
use DBI;
use Encode;
binmode STDIN, ':utf8';
binmode STDOUT, ':utf8';
binmode STDERR, ':utf8';
$SIG{__WARN__} = sub {
my $w = join ' ', @_;
print "Warning not decoded: $w\n";
print "Warning decoded: " . Encode::decode('UTF-8', $w) . "\n";
};
$SIG{__DIE__} = sub {
my $w = join ' ', @_;
print "Error not decoded: $w\n";
print "Error decoded: " . Encode::decode('UTF-8', $w) . "\n";
};
my $dbh = DBI->connect('dbi:Pg:database=mbkivilinet;host=localhost', 'postgres', '', { pg_enable_utf8 => 1 }) or die;
my ($val) = $dbh->selectrow_array("SELECT 'hallöle'");
print "Value: $val\n";
$dbh->do("SELECT asdasd FROM qweqweqwe");
$dbh->{RaiseError} = 1;
$dbh->do("SELECT asdasd FROM qweqweqwe");
$dbh->disconnect;
Kind regards,
mosu
Message body not shown because it is not plain text.