在本例中,Firebird返回未解码的字符串。我是否没有正确设置数据库,或者这是火鸟的工作方式?
#!/usr/bin/env perl
use warnings;
use 5.10.0;
use utf8;
use open qw( :std :utf8 );
use Devel::Peek;
use DBI;
my ( $db, $dbh, $sth, @array );
my $table = 'test_encoding';
my $create = "CREATE TABLE $table ( name varchar(32) )";
my $insert = "INSERT INTO $table ( name ) VALUES ( ? )";
my $select = "SELECT * FROM $table";
my $value = 'ä';
$db = '/home/me/my_firebird_db';
$dbh = DBI->connect(
"dbi:Firebird:db=$db", 'user', 'password',
{ PrintError => 0, RaiseError => 1, ib_charset => 'UTF-8' }
);
$sth = $dbh->do( "DROP TABLE $table" );
$sth = $dbh->do( $create );;
$sth = $dbh->prepare( $insert );
$sth->execute( $value );
@array = $dbh->selectrow_array( $select );
Dump $array[0];
say $array[0];
say "";
$db = '/home/me/my_sqlite_db';
$dbh = DBI->connect(
"dbi:SQLite:db=$db", '', '',
{ PrintError => 0, RaiseError => 1, sqlite_string_mode => 5 }
);
$sth = $dbh->do( "DROP TABLE IF EXISTS $table" );
$sth = $dbh->do( $create );
$sth = $dbh->prepare( $insert );
$sth->execute( $value );
@array = $dbh->selectrow_array( $select );
Dump $array[0];
say $array[0];
输出:
SV = PV(0x2105360) at 0x22628a0
REFCNT = 1
FLAGS = (POK,pPOK)
PV = 0x22a37e0 "303244"