Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Dump data from unicode database

by bliako (Monsignor)
on Jun 30, 2021 at 11:18 UTC ( [id://11134482]=note: print w/replies, xml ) Need Help??


in reply to Dump data from unicode database

try telling perl to use the correct encoding for STDOUT (which is where print "zbzb" prints) with binmode(STDOUT, ":utf8"); . Add to STDERR as needed.

Replies are listed 'Best First'.
Re^2: Dump data from unicode database
by Tux (Canon) on Jun 30, 2021 at 12:42 UTC

    Please do not promote :utf8! Use the correct :encoding(utf-8) instead from now on.


    Enjoy, Have FUN! H.Merijn
Re^2: Dump data from unicode database
by sachin raj aryan (Acolyte) on Jun 30, 2021 at 12:29 UTC
    my $sql1 = "select deptid,to_char(a.epfno) epfno,a.ename ename,desi +g,decode(b.status,'P','उपस्थि&#23 +40;','A','अवकाश','D','प्&#2 +352;तिनियुक्त&# +2367;') status,b.rmk from Atnd_emp_mast a,Atnd_position b where repoid=1 and I +SACTIVE=0 and a.epfno=b.epfno and SUMM_HOD_FLAG=1 and ATTEN_DT=to_date('17-12-2020','DD-MM-YYYY') order by SUMM_SORTID"; + $sth =$dbh->prepare($sql1); $sth->execute(); my @rows =$sth->fetchrow_array; while (@rows=$sth->fetchrow_array) { binmode(STDOUT, ":utf8"); print join(",",@row),"\n"; }

    made changes its still not working

      ENOTENOUGHINFO: you have told us nothing about the database, its version, its encoding, its network layers etc etc.

      $ cat info.csv id,count,desc,asc,row 1,2,foo,bar,10 $ perl -MDBI -COE -wE'my$dbh=DBI->connect("dbi:CSV:",undef,undef,{f_ex +t=>".csv/r"});my$sth=$dbh->prepare("select id,\x27\x{20ac}\x27 from i +nfo");$sth->execute;while(my$r=$sth->fetch){say for@$r;}' 1 €

      That just worked, so it could be your database or your database driver, or your database driver version or ...


      Enjoy, Have FUN! H.Merijn

      is the DB set up to store unicode? is what you store in DB unicode? is what you get out from DB encoded as unicode?

      placing a binmode(STDOUT, ":encoding(utf-8)"); (thanks Tux) at the beginning of your script will display unicode to STDOUT and complain if it contains invalid bytes. But you may need to tell your db to store unicode (for mysql it used to be something like this during table construction: mysql_enable_utf8mb4) and make DBI::connect aware with mysql_enable_utf8 => 1. For some cases you need to explicitly encode the bytes received from DB into unicode using Encode::encode... or investigate if it's a case of double encoding using Encode::decode...

    A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11134482]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-03-29 02:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found