From: Matthias Apitz <guru@unixarea.de>
To: Christoph Moench-Tegeder <cmt@burggraben.net>
To: pgsql-general@lists.postgresql.org
Subject: Re: Perl DBI converts UTF-8 again to UTF-8 before sending it to the server
Date: Fri, 11 Oct 2019 16:08:08 +0200
Message-ID: <20191011140808.GA6717@c720-r342378> (raw)
In-Reply-To: <20191004150749.GB3724@c720-r342378>
References: <20191004132529.GA2871@c720-r342378>
<20191004142932.GA2532@elch.exwg.net>
<20191004150749.GB3724@c720-r342378>
Christoph,
May I come back to the UTF-8 problem, but now for the reading aspect:
I connect to the PG server with:
$dbh = DBI->connect($PGDB, $PGDB_USER, $PGDB_PASS,
{ pg_utf8_flag => 1,
pg_enable_utf8 => 1,
AutoCommit => 0,
RaiseError => 0,
PrintError => 0,
}
);
and do a SELECT for a column which contains UTF-8 data (I double checked
this with SQL and ::bytea):
$sth=$dbh->prepare(
"select d02name from d02ben where d02bnr = '00001048313'")
or die "parse error\n".$DBI::errstr."\n";
$sth->execute
or die "exec error\n".$DBI::errstr."\n";
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:
HexStr: 50e46461676f67697363686520486f6368736368756c65205765696e67617274656e2020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020
P<E4>dagogische Hochschule Weingarten
Following the man page of DBD::Pg the attribute pg_enable_utf8 => 1
should ensure that strings are returned from DBI with the UTF-8 flag
switched on. The server sends the string in UTF-8 as I can see with
strace:
...
recvfrom(3, "T\0\0\0 \0\1d02name\0\0\1\313\237\0\3\0\0\4\22\377\377\0\0\0|\0\0D\0\0\0\203\0\1\0\0\0yP\303\244dagogische Hochschule Weingarten C\0\0\0\rSELECT 1\0Z\0\0\0\5T", 16384, 0, NULL, NULL) = 185
write(1, "HexStr: 50e46461676f67697363686520486f6368736368756c65205765696e67617274656e2020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020\n", 249) = 249
write(1, "P\344dagogische Hochschule Weingarten
But why it gets translated to ISO?
Thanks for your help again.
matthias
--
Matthias Apitz, ✉ guru@unixarea.de, http://www.unixarea.de/ +49-176-38902045
Public GnuPG key: http://www.unixarea.de/key.pubAttachments:
signature.asc (application/pgp-signature, 832B) download
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: guru@unixarea.de, cmt@burggraben.net
Subject: Re: Perl DBI converts UTF-8 again to UTF-8 before sending it to the server
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>
* 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