Re: Perl DBI converts UTF-8 again to UTF-8 before sending it to theserver

Поиск
Список
Период
Сортировка
От Matthias Apitz
Тема Re: Perl DBI converts UTF-8 again to UTF-8 before sending it to theserver
Дата
Msg-id 20191011140808.GA6717@c720-r342378
обсуждение исходный текст
Ответ на Re: Perl DBI converts UTF-8 again to UTF-8 before sending it to theserver  (Matthias Apitz <guru@unixarea.de>)
Ответы Re: Perl DBI converts UTF-8 again to UTF-8 before sending it to theserver  (Christoph Moench-Tegeder <cmt@burggraben.net>)
Список pgsql-general
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
HochschuleWeingarten
C\0\0\0\rSELECT1\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.pub

Вложения

В списке pgsql-general по дате отправления:

Предыдущее
От: Adrian Klaver
Дата:
Сообщение: Re: Too many SET TimeZone and Application_name queries
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Issues with PAM : log that it failed, whether it actually failed or not