From: Christoph Moench-Tegeder <cmt@burggraben.net>
To: Matthias Apitz <guru@unixarea.de>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Perl DBI converts UTF-8 again to UTF-8 before sending it to the server
Date: Sat, 12 Oct 2019 15:14:24 +0200
Message-ID: <20191012131424.GA2452@elch.exwg.net> (raw)
In-Reply-To: <20191011140808.GA6717@c720-r342378>
References: <20191004132529.GA2871@c720-r342378>
<20191004142932.GA2532@elch.exwg.net>
<20191004150749.GB3724@c720-r342378>
<20191011140808.GA6717@c720-r342378>
## Matthias Apitz (guru@unixarea.de):
> but when I now fetch the first row with:
>
> @row = $sth->fetchrow_array;
> $HexStr = unpack("H*", $row[0]);
> print "HexStr: " . $HexStr . "\n";
> print "$row[0]\n";
>
> The resulting column contains ISO data:
As expected: https://perldoc.perl.org/perluniintro.html
Specifically, if all code points in the string are 0xFF or less, Perl
uses the native eight-bit character set.
> P<E4>dagogische Hochschule Weingarten
And then it doesn't know that your terminal expects UTF-8 (perl
just dumps the binary string here), because you didn't tell it:
"binmode(STDOUT, ':encoding(utf8)')" would fix that.
See: https://perldoc.perl.org/perlunifaq.html specifically "What if I
don't decode?", "What if I don't encode?" and "Is there a way to
automatically decode or encode?".
The whole PostgreSQL-DBI-UTF8-thingy is working: use "Tijl Müller"
as test data (that's the dutch "ij"-digraph in there, a character
decidedly not in "latin-9/15" and therefore not "0xFF or less").
That will break your "unpack('H*')" - it tries to unpack that wide
character into a hex byte and "Character in 'H' format wrapped in
unpack". Use "print(join(' ', unpack('U*', $row[0])))" to see that
the ij has codepoint 307 (decimal).
Regards,
Christoph
--
Spare Space
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: cmt@burggraben.net, guru@unixarea.de
Subject: Re: Perl DBI converts UTF-8 again to UTF-8 before sending it to the server
In-Reply-To: <20191012131424.GA2452@elch.exwg.net>
References: <20191004132529.GA2871@c720-r342378> <20191004142932.GA2532@elch.exwg.net> <20191004150749.GB3724@c720-r342378> <20191011140808.GA6717@c720-r342378> <20191012131424.GA2452@elch.exwg.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox