Re: any known DBD::pg change caused this utf8 issue?
[email protected] (Shaomei Liu) Thu, 19 Dec 2024 16:16:17 -0500
| Newsgroups | perl.dbd.pg |
|---|---|
| Message-ID | <CAK70g6Mx+F++aP2mXwrtN=k=yUt9958rr39KAW8CM_eO8pMhhg@mail.gmail.com> |
--00000000000024adb30629a60b9d Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Thank you, Christoph! perl -MDBD::Pg -e'print $DBD::Pg::VERSION' EL8 3.7.4 EL7 2.19.3 On Thu, Dec 19, 2024 at 2:13=E2=80=AFPM Christoph Lamprecht < [email protected]> wrote: > 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 pg_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]= m>> > > 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 =E2=80=9C is dis= played 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 > respectively. > > 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 de= code, Database > > shows =E2=80=9C on EL7 but =C3=A2\u0080\u009C on EL8 > > my @values =3D ($chars); #=3D=3D=3D=3D=3D=3D>with decode, = 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 > > --------------- > > =C3=A2\u0080\u009C =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D>NOK wit= hout decode > > =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 > > --------------- > > =E2=80=9C =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D>OK with= out decode > > =E2=80=9C =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D>OK with= decode > > (2 rows) > > > --00000000000024adb30629a60b9d Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr">Thank you, Christoph!<div><div style=3D"color:rgb(204,204,= 204);background-color:rgb(31,31,31);font-family:Consolas,"Courier New&= quot;,monospace;font-size:14px;line-height:19px;white-space:pre"><div><span= style=3D"color:rgb(206,145,120)">perl -MDBD::Pg -e'print $DBD::Pg::VER= SION'</span></div><div><span style=3D"color:rgb(206,145,120)">EL8 3.7.4= </span></div><div><span style=3D"color:rgb(206,145,120)">EL7 2.19.3</span><= /div></div></div></div><br><div class=3D"gmail_quote gmail_quote_container"= ><div dir=3D"ltr" class=3D"gmail_attr">On Thu, Dec 19, 2024 at 2:13=E2=80= =AFPM Christoph Lamprecht <<a href=3D"mailto:christoph.lamprecht@online.= de">[email protected]</a>> wrote:<br></div><blockquote class= =3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rg= b(204,204,204);padding-left:1ex">What does the following print:<br> <br> perl -MDBD::Pg -e'print $DBD::Pg::VERSION'<br> <br> <br> Am 19.12.24 um 17:05 schrieb Shaomei Liu:<br> > thank you, Warstone!<br> > EL8 pg_lib_version 120001 pg_enable_utf8:1<br> > EL7 pg_lib_version: 90224 =C2=A0pg_enable_utf8:1<br> > not sure if that is the version you asked though.<br> > Shirley<br> ><br> > On Wed, Dec 18, 2024 at 10:32=E2=80=AFPM <a href=3D"mailto:Warstone@li= st.ru" target=3D"_blank">[email protected]</a><br> > <mailto:<a href=3D"mailto:[email protected]" target=3D"_blank">Warst= [email protected]</a>> <<a href=3D"mailto:[email protected]" target=3D"_blan= k">[email protected]</a> <mailto:<a href=3D"mailto:[email protected]" targ= et=3D"_blank">[email protected]</a>>><br> > wrote:<br> ><br> >=C2=A0 =C2=A0 =C2=A0Can you provide DBD::Pg versions for your EL7 and E= L8 distros? And<br> >=C2=A0 =C2=A0 =C2=A0check this flag:<br> >=C2=A0 =C2=A0 =C2=A0<a href=3D"https://metacpan.org/pod/DBD::Pg#pg_enab= le_utf8-(integer)" rel=3D"noreferrer" target=3D"_blank">https://metacpan.or= g/pod/DBD::Pg#pg_enable_utf8-(integer)</a><br> >=C2=A0 =C2=A0 =C2=A0<<a href=3D"https://metacpan.org/pod/DBD::Pg#pg_= enable_utf8-(integer)" rel=3D"noreferrer" target=3D"_blank">https://metacpa= n.org/pod/DBD::Pg#pg_enable_utf8-(integer)</a>><br> ><br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=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<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0<<a href=3D"mailto:sliu.newjersey@= gmail.com" target=3D"_blank">[email protected]</a> <mailto:<a hre= f=3D"mailto:[email protected]" target=3D"_blank">sliu.newjersey@gmai= l.com</a>>>:<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0send again after subscribing.<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0On Wed, Dec 18, 2024 at 11:20AM Shaom= ei Liu<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0<<a href=3D"mailto:sliu.newjersey@= gmail.com" target=3D"_blank">[email protected]</a><br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0<//<a href=3D"http://e.mail.ru/com= pose/?mailto=3Dmailto%[email protected]" rel=3D"noreferrer" target= =3D"_blank">e.mail.ru/compose/?mailto=3Dmailto%[email protected]</= a>>><br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0wrote:<br> ><br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Hello,<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0I have a project which = uses DBI to write to postgres DB.<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0after upgrading from RH= EL7 to RHEL8, the utf-8 character is<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0not displayed properly = in the DB. DB has correct utf-8<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0encoding set.<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0for example, left doubl= e quotation mark=C2=A0 =C2=A0=E2=80=9C=C2=A0 is displayed as<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=C3=A2\u0080\u009C.<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0with support from DBI c= ommunity, the issue was solved by<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0calling decode from Enc= ode module before writing to DB.<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0wondering what is the c= hange from DBD::pg cause this issue.<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0perl version is 5.26.3 = and 5.16.3 on EL8 and EL7 respectively.<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0DBI version is 1.641 an= d 1.627 on EL8 and EL7 respectively.<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0here is the program and= execution results.<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Any feedback are greatl= y appreciated!<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0thank you<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Shirley<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0<a href=3D"http://xxx.c= om" rel=3D"noreferrer" target=3D"_blank">xxx.com</a>> cat <a href=3D"htt= p://testutf_decode.pl" rel=3D"noreferrer" target=3D"_blank">testutf_decode.= pl</a><br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0#!/usr/bin/perl<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0use strict;<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0use warnings;<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0use DBI;<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0use Encode 'decode&= #39;;<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0print "DBI version= : $DBI::VERSION\n";<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0my $db =3D "debugu= tf";<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0my $host =3D "db&q= uot;;<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0my $user =3D "post= gres";<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0my $pass =3D "&quo= t;;<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0my $dbh =3D<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0DBI->connect("D= BI:Pg:dbname=3D$db;host=3D$host",$user,$pass);<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0my $sql =3D 'INSERT= INTO table1 (title) VALUES (?)';<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0my $query =3D $dbh->= prepare($sql);<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0my $bytes =3D '=E2= =80=9C';<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0my $chars =3D decode(&#= 39;UTF-8', $bytes);<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0print "$bytes cont= ains ".length($bytes)." characters\n";<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0print "after decod= e $bytes contains ".length($chars)."<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0characters\n";<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0#my @values =3D ($bytes= ); #=3D=3D=3D=3D=3D=3D=3D>without decode, Database<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0shows =E2=80=9C on EL7 = but =C3=A2\u0080\u009C on EL8<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0my @values =3D ($chars)= ; =C2=A0#=3D=3D=3D=3D=3D=3D>with decode, Database shows<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=E2=80=9C on both EL8 a= nd EL7, decode fixed the issue<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0$query->execute(@val= ues);<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0############### running= on EL8<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0<a href=3D"http://xxx.c= om" rel=3D"noreferrer" target=3D"_blank">xxx.com</a>> ./<a href=3D"http:= //testutf_decode.pl" rel=3D"noreferrer" target=3D"_blank">testutf_decode.pl= </a><br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0DBI version: 1.641<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=E2=80=9C contains 3 ch= aracters<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0after decode =E2=80=9C = contains 1 characters<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0[<a href=3D"http://yyy.= com" rel=3D"noreferrer" target=3D"_blank">yyy.com</a>]$ psql -Upostgres -hd= b debugutf<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0psql (16.6)<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0debugutf=3D# select * f= rom table1;<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0title<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0---------------<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=C3=A2\u0080\u00= 9C =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D>NOK without decode<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =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 is= sue<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(2 rows)<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0############### running= on EL7<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0<a href=3D"http://xxx.c= om" rel=3D"noreferrer" target=3D"_blank">xxx.com</a>> ./<a href=3D"http:= //testutf_decode.pl" rel=3D"noreferrer" target=3D"_blank">testutf_decode.pl= </a><br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0DBI version: 1.627<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=E2=80=9C contains 3 ch= aracters<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0after decode =E2=80=9C = contains 1 characters<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0[<a href=3D"http://yyy.= com" rel=3D"noreferrer" target=3D"_blank">yyy.com</a>]$ psql -Upostgres -hd= b debugutf<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0psql (16.6)<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0debugutf=3D# select * f= rom table1;<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0title<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0---------------<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=E2=80=9C =3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D>OK without decode<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=E2=80=9C =3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D>OK with decode<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(2 rows)<br> ><br> </blockquote></div> --00000000000024adb30629a60b9d--