Re: any known DBD::pg change caused this utf8 issue?

[email protected] (Christoph Lamprecht) Thu, 19 Dec 2024 20:13:12 +0100
Newsgroups perl.dbd.pg
Message-ID <[email protected]>
What does the following print:

perl -MDBD::Pg -e'print $DBD::Pg::VERSION'


Am 19.12.24 um 17:05 schrieb Shaomei Liu:
> thank you, Warstone!
> EL8 pg_lib_version 120001 pg_enable_utf8:1
> EL7 pg_lib_version: 90224 =C2=A0pg_enable_utf8:1
> not sure if that is the version you asked though.
> Shirley
>
> On Wed, Dec 18, 2024 at 10:32=E2=80=AFPM [email protected]
> <mailto:[email protected]> <[email protected] <mailto:[email protected]>>
> wrote:
>
>     Can you provide DBD::Pg versions for your EL7 and EL8 distros? And
>     check this flag:
>     https://metacpan.org/pod/DBD::Pg#pg_enable_utf8-(integer)
>     <https://metacpan.org/pod/DBD::Pg#pg_enable_utf8-(integer)>
>
>         =D0=A7=D0=B5=D1=82=D0=B2=D0=B5=D1=80=D0=B3, 19 =D0=B4=D0=B5=D0=
=BA=D0=B0=D0=B1=D1=80=D1=8F 2024, 0:34 +03:00 =D0=BE=D1=82 Shaomei Liu
>         <[email protected] <mailto:[email protected]>>:
>         send again after subscribing.
>         On Wed, Dec 18, 2024 at 11:20AM Shaomei Liu
>         <[email protected]
>         <//e.mail.ru/compose/?mailto=3Dmailto%[email protected]=
>>
>         wrote:
>
>             Hello,
>             I have a project which uses DBI to write to postgres DB.
>             after upgrading from RHEL7 to RHEL8, the utf-8 character is
>             not displayed properly in the DB. DB has correct utf-8
>             encoding set.
>             for example, left double quotation mark=C2=A0 =C2=A0=E2=80=
=9C=C2=A0 is displayed as
>             =C3=A2\u0080\u009C.
>             with support from DBI community, the issue was solved by
>             calling decode from Encode module before writing to DB.
>             wondering what is the change from DBD::pg cause this issue.
>             perl version is 5.26.3 and 5.16.3 on EL8 and EL7 respectivel=
y.
>             DBI version is 1.641 and 1.627 on EL8 and EL7 respectively.
>             here is the program and execution results.
>             Any feedback are greatly appreciated!
>             thank you
>             Shirley
>             xxx.com> cat testutf_decode.pl
>             #!/usr/bin/perl
>             use strict;
>             use warnings;
>             use DBI;
>             use Encode 'decode';
>             print "DBI version: $DBI::VERSION\n";
>             my $db =3D "debugutf";
>             my $host =3D "db";
>             my $user =3D "postgres";
>             my $pass =3D "";
>             my $dbh =3D
>             DBI->connect("DBI:Pg:dbname=3D$db;host=3D$host",$user,$pass)=
;
>             my $sql =3D 'INSERT INTO table1 (title) VALUES (?)';
>             my $query =3D $dbh->prepare($sql);
>             my $bytes =3D '=E2=80=9C';
>             my $chars =3D decode('UTF-8', $bytes);
>             print "$bytes contains ".length($bytes)." characters\n";
>             print "after decode $bytes contains ".length($chars)."
>             characters\n";
>             #my @values =3D ($bytes); #=3D=3D=3D=3D=3D=3D=3D>without dec=
ode, Database
>             shows =E2=80=9C on EL7 but =C3=A2\u0080\u009C on EL8
>             my @values =3D ($chars); =C2=A0#=3D=3D=3D=3D=3D=3D>with deco=
de, Database shows
>             =E2=80=9C on both EL8 and EL7, decode fixed the issue
>             $query->execute(@values);
>             ############### running on EL8
>             xxx.com> ./testutf_decode.pl
>             DBI version: 1.641
>             =E2=80=9C contains 3 characters
>             after decode =E2=80=9C contains 1 characters
>             [yyy.com]$ psql -Upostgres -hdb debugutf
>             psql (16.6)
>             debugutf=3D# select * from table1;
>             title
>             ---------------
>              =C2=A0=C3=A2\u0080\u009C =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D>NOK=
 without decode
>              =C2=A0=E2=80=9C =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D>OK =
with decode, so decode fixed the issue
>             (2 rows)
>             ############### running on EL7
>             xxx.com> ./testutf_decode.pl
>             DBI version: 1.627
>             =E2=80=9C contains 3 characters
>             after decode =E2=80=9C contains 1 characters
>             [yyy.com]$ psql -Upostgres -hdb debugutf
>             psql (16.6)
>             debugutf=3D# select * from table1;
>             title
>             ---------------
>              =C2=A0=E2=80=9C =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D>OK =
without decode
>              =C2=A0=E2=80=9C =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D>OK =
with decode
>             (2 rows)
>