#!/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 encoded. use DBI; use DBD::SQLite::Constants ':dbd_sqlite_string_mode'; # A constant used 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"; }