need help with utf-8
[email protected] (Shaomei Liu) Mon, 16 Dec 2024 17:12:32 -0500
| Newsgroups | perl.dbi.users |
|---|---|
| Message-ID | <CAK70g6Mb61FXkSuJ2BgOuDrS1s3jP=qgdUBJ9Xj4Nac-tgCvEg@mail.gmail.com> |
--000000000000c1d36306296a7ada
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Hello,
very happy to find this mailing list as it is my last resort!!
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 displayed as =C3=A2=
\u0080\u009C.
You can use this link to check hex utf-8 bytes
https://www.cogsci.ed.ac.uk/~richard/utf-8.cgi?input=3D%E2%80%9C&mode=3Dcha=
r
below is the file testutf.pl which writes left double quotation mark =E2=
=80=9C to
the database. it also shows the query results from psql for both EL8 and
EL7.
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3Dfile testutf.pl=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
#!/usr/bin/perl
use strict;
use warnings;
use DBI;
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 @values =3D ('=E2=80=9C');
$query->execute(@values);
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3Don RHEL8
#execute testutf.pl which wrote =E2=80=9C to database on RHEL8
text.tac1.dev.bia-boeing.com> ./testutf.pl
DBI version: 1.641
#from psql
debugutf=3D# select * from table1;
title
---------------
=C3=A2\u0080\u009C =3D=3D=3D=3D=3D=3D=3D=3D=3D>unexpected
(1 row)
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3Don RHEL7
#execute testutf.pl which wrote =E2=80=9C to database on RHEL8
text.tac1.dev.bia-boeing.com> ./testutf.pl
DBI version: 1.627
#from psql
debugutf=3D# select * from table1;
title
---------------
=E2=80=9C =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D>expected
(1 row)
Any feedback is appreciated.
thank you
Shirley
--000000000000c1d36306296a7ada
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Hello,<br>very happy to find this mailing list as it is my=
last resort!!<div>I have a project which uses DBI to write to postgres DB.=
</div><div>after upgrading from RHEL7 to RHEL8, the utf-8 character is not =
displayed properly in the DB. DB has correct utf-8 encoding set.</div><div>=
for example, left double quotation mark=C2=A0 =C2=A0=E2=80=9C=C2=A0 is disp=
layed as=C2=A0<span style=3D"background-color:rgb(31,31,31);color:rgb(204,2=
04,204);font-family:Consolas,"Courier New",monospace;font-size:14=
px;white-space:pre">=C3=A2\u0080\u009C</span>.</div><div>You can use this l=
ink to check hex utf-8 bytes</div><div><a href=3D"https://www.cogsci.ed.ac.=
uk/~richard/utf-8.cgi?input=3D%E2%80%9C&mode=3Dchar">https://www.cogsci=
.ed.ac.uk/~richard/utf-8.cgi?input=3D%E2%80%9C&mode=3Dchar</a></div><di=
v><br></div><div>below is the file <a href=3D"http://testutf.pl">testutf.pl=
</a> which writes left double quotation mark=C2=A0
=E2=80=9C to the database. it also shows the query results from psql for bo=
th EL8 and EL7.<br><br>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3Dfile <a href=3D"http:/=
/testutf.pl">testutf.pl</a>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D<br>#!/usr/bin/per=
l<br>use strict;<br>use warnings;<br>use DBI;<br>print "DBI version: $=
DBI::VERSION\n";<br><br>my $db =3D "debugutf";<br>my $host =
=3D "db";<br>my $user =3D "postgres";<br>my $pass =3D &=
quot;";<br>my $dbh =3D DBI->connect("DBI:Pg:dbname=3D$db;host=
=3D$host",$user,$pass);<br>my $sql =3D 'INSERT INTO table1 (title)=
VALUES (?)';<br>my $query =3D $dbh->prepare($sql);<br>my @values =
=3D ('=E2=80=9C');<br>$query->execute(@values);<br>=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D<br><br>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3Don RHEL=
8<br>#execute <a href=3D"http://testutf.pl">testutf.pl</a> which wrote =E2=
=80=9C to database on RHEL8<br><a href=3D"http://text.tac1.dev.bia-boeing.c=
om">text.tac1.dev.bia-boeing.com</a>> ./<a href=3D"http://testutf.pl">te=
stutf.pl</a><br>DBI version: 1.641<br><br>#from psql<br>debugutf=3D# select=
* from table1;<br>=C2=A0 =C2=A0 =C2=A0title<br>---------------<br>=C2=A0<f=
ont color=3D"#ff0000">=C3=A2\u0080\u009C=C2=A0 =3D=3D=3D=3D=3D=3D=3D=3D=3D&=
gt;unexpected</font><br>(1 row)<br><br><br>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3Don RHEL7<br>#execute <a href=3D"http://testutf.pl">testutf.pl</=
a> which wrote =E2=80=9C to database on RHEL8<br><a href=3D"http://text.tac=
1.dev.bia-boeing.com">text.tac1.dev.bia-boeing.com</a>> ./<a href=3D"htt=
p://testutf.pl">testutf.pl</a><br>DBI version: 1.627<br><br>#from psql<br>d=
ebugutf=3D# select * from table1;<br>=C2=A0 =C2=A0 =C2=A0title<br>---------=
------<br><font color=3D"#0000ff">=C2=A0=E2=80=9C=C2=A0 =C2=A0 =C2=A0 =C2=
=A0=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D>expected</font><br>(1 row)</div>=
<div><br></div><div>Any feedback is appreciated.</div><div>thank you</div><=
div>Shirley</div></div>
--000000000000c1d36306296a7ada--