Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: Need tipps for identifying utf-8 problems with Dancer and MySQL

by kwetal (Initiate)
on Jun 17, 2014 at 14:32 UTC ( #1090152=note: print w/ replies, xml ) Need Help??


in reply to Re: Need tipps for identifying utf-8 problems with Dancer and MySQL
in thread Need tipps for identifying utf-8 problems with Dancer and MySQL

Thanks for the advice on utf8::is_utf8! I stumbled on the same problem, but I am using sqlite3. When reading the string from the database, I can see that it contains the right bytes(*), but the utf8_flag is 0.

How do I convince Perl that the string from the database is really an utf8 string? I think that I need to open the sqlite database with some option so that all strings read from the database will receive the utf8-flag.

I tried utf8::upgrade, but it does not work: on the web page the single accented character shows up as 2 accented characters.

(*)printing to STDERR which is connected to an utf8 terminal shows the correct accented character.


Comment on Re^2: Need tipps for identifying utf-8 problems with Dancer and MySQL
Re^3: Need tipps for identifying utf-8 problems with Dancer and MySQL
by McA (Priest) on Jun 17, 2014 at 18:38 UTC

    Hi,

    First of all I don't know sqlite3. There are some players in the game: sqlite3 and DBD::xxx. When the DBD driver for sqlite you use does not decode the byte strings which come from the sqlite database, than you have to do it.

    use Encode qw(decode); my $decoded_string = decode('UTF-8', $byte_string_from_sqlite);

    Which driver 'DBD::xxx' are you using?

    UPDATE: Have a look at http://search.cpan.org/~ishigaki/DBD-SQLite/lib/DBD/SQLite.pm#DRIVER_PRIVATE_ATTRIBUTES. I'm pretty sure that is what you are looking for: sqlite_unicode

    Regards
    McA

      $dbh->{sqlite_unicode} = 1;

      Well yes! That's exactly the answer to my problem. Thank you very much.

      That explains why I couldn't find it in perldoc DBD; clearly I was browsing the wrong doc.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2015-07-05 14:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (67 votes), past polls