in reply to SQLite returns funny characters

You need to tell Perl and SQLite that you're using UTF-8:
#!/usr/bin/perl use warnings; use strict; use feature qw{ say }; use utf8; # Source code contains non-ASCII UTF-8 characters. use open IO => ':encoding(UTF-8)', ':std'; # Output should be UTF-8 e +ncoded. use DBI; use DBD::SQLite::Constants ':dbd_sqlite_string_mode'; # A constant us +ed below. my $dbh = 'DBI'->connect('dbi:SQLite:dbname=:memory:', "", "", { # This tells the db driver to use Unicode. sqlite_string_mode => DBD_SQLITE_STRING_MODE_UNICODE_STRICT }); $dbh->do('CREATE TABLE t1 (temperature INT, degree TEXT)'); my $insert = $dbh->prepare( 'INSERT INTO t1 (temperature, degree) VALUES (?, ?)'); $insert->execute(10, '°C'); $insert->execute(80, '°F'); my $select = $dbh->prepare('SELECT * FROM t1'); $select->execute; while (my @row = $select->fetchrow_array) { say "@row"; }
map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Replies are listed 'Best First'.
Re^2: SQLite returns funny characters
by jmClifford (Beadle) on Jul 10, 2024 at 05:39 UTC

    Thanks to Choroba for the contained sample. My issue now is:

    Can't continue after import errors "dbd_sqlite_string_mode" is not defined in %DBD::SQLite::Constants::EX +PORT_TAGS

    I can assess SQLite DBs with other Perl files. Is this a case of updating to the latest ? I don't think I have ever "CSPAN"ed a DBD module onto my Win10 system.

    Regards JC....

      What version of DBD::SQLite is installed?

      map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

        Hi. I just upgrade to version DBD::SQLite 1.74. I suspect it was not installed. However, the previous problem went away. The new problem is;

        $insert->execute(10, '°C'); $insert->execute(80, '°F'); with error messages for both lines UTF-8 "\xB0" does not map to Unicode

        The other (following) response with this thread by roho I suspect may be the answer here. I am unsure of how to implement his/her recommendation.

        Regards JC.....