in reply to My UTF-8 text isn't surviving I/O as expected
By default, DBD::SQLite uses a setting which is wrong (see the documentation for details). To fix it, only slight changes are needed:
use DBD::SQLite::Constants ':dbd_sqlite_string_mode'; my $dbh = DBI->connect( "dbi:SQLite:dbname=:memory:", "", "", {RaiseError => 1, AutoCommit => 1, sqlite_string_mode => DBD_SQLITE_STRING_MODE_UNICODE_STRICT });
PerlMonks is very old and its <code> sections can't handle Unicode. Either use <pre> instead, or replace unicode characters in the source code by their names:
my $utf8_text1 = "\N{LATIN CAPITAL LETTER A WITH RING ABOVE}ke Lindstr +\N{LATIN SMALL LETTER O WITH DIAERESIS}m";
BTW, get into the habit of using placeholders to insert values to prevent SQL injection:
my $insert = $dbh->prepare('INSERT INTO names VALUES(?, ?)'); $insert->execute('nm0512537', $utf8_text1);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: My UTF-8 text isn't surviving I/O as expected
by ibm1620 (Hermit) on Nov 23, 2024 at 22:35 UTC | |
by choroba (Cardinal) on Nov 23, 2024 at 22:50 UTC |