Re: Perl DBI converts UTF-8 again to UTF-8 before sending it to theserver - Mailing list pgsql-general

From Matthias Apitz
Subject Re: Perl DBI converts UTF-8 again to UTF-8 before sending it to theserver
Date
Msg-id 20191004150749.GB3724@c720-r342378
Whole thread Raw
In response to Re: Perl DBI converts UTF-8 again to UTF-8 before sending it to theserver  (Christoph Moench-Tegeder <cmt@burggraben.net>)
Responses Re: Perl DBI converts UTF-8 again to UTF-8 before sending it to theserver
Re: Perl DBI converts UTF-8 again to UTF-8 before sending it to theserver
List pgsql-general
El día viernes, octubre 04, 2019 a las 04:29:32p. m. +0200, Christoph Moench-Tegeder escribió:

> ## Matthias Apitz (guru@unixarea.de):
>
> > my $text = "\xc3\xa4";
> > print "text: ".$text."\n";
>
> Your output is lying to you:
> you need a binmode(STDOUT, ':encoding(utf8)'), which will make this print
> "ä", and a utf8::decode($text), after which you get "ä". And when you
> pass that $text through DBD::Pg, it will still be an "ä". And when you
> change $text to "ä", it still works. Most other combinations will
> either fail with "\xc3\xa4" or "ä".

Thanks, but:

...
my $text = "ä \xc3\xa4";
print "text before STDOUT set to UTF-8: ".$text."\n";
binmode(STDOUT, ':encoding(utf8)');
print "text after STDOUT set to UTF-8: ".$text."\n";
utf8::decode($text);
print "text after utf8::decode(\$text): ".$text."\n";
$sth->execute($text, 1) or die $sth->errstr, "\n";

gives:


./utf8.pl
text before STDOUT set to UTF-8: ä
text after STDOUT set to UTF-8: ä ä
text after utf8::decode($text): ä ä
printf "select tstchar25::bytea from dbctest ;\n" | psql -Usisis -dnewsisis
                         tstchar25
------------------------------------------------------------
 \xc3a420c383c2a4202020202020202020202020202020202020202020
(1 Zeile)

> Welcome to modern perl's handling of utf8. Cue "Everything is Fine" meme.

Seems so :-(

    matthias


--
Matthias Apitz, ✉ guru@unixarea.de, http://www.unixarea.de/ +49-176-38902045
Public GnuPG key: http://www.unixarea.de/key.pub

3. Oktober! Wir gratulieren! Der Berliner Fernsehturm wird 50
aus: https://www.jungewelt.de/2019/10-02/index.php

Attachment

pgsql-general by date:

Previous
From: Andres Freund
Date:
Subject: Re: Postgres 12: backend crashes when creating non-deterministiccollation
Next
From: Christoph Moench-Tegeder
Date:
Subject: Re: Perl DBI converts UTF-8 again to UTF-8 before sending it to theserver