DBD :: Firebird编码/解码
在此示例中,Firebird返回了未编码的字符串。我是否没有正确设置数据库,或者这是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 "\303\244"\0
CUR = 2
LEN = 10
ä
SV = PV(0x2111470) at 0x2121220
REFCNT = 1
FLAGS = (POK,pPOK,UTF8)
PV = 0x1f2fed0 "\303\244"\0 [UTF8 "\x{e4}"]
CUR = 2
LEN = 10
ä
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如 dbd :: firebird clamp 在注释中,您需要使用
以下方式连接:
ib_charset
属性必须在连接字符串中,不在哈希中,其值必须为utf8
(不是utf-8
!),并且您需要在设置ib_enable_utf8 > 1 到哈希。
具体而言,此部分:
As indicated by the link to the documentation of DBD::Firebird supplied by clamp in the comments, you need to connect using:
That is, the
ib_charset
property must be in the connection string, not in the hash, and its value must beUTF8
(notUTF-8
!), and you need to addib_enable_utf8
with setting1
to the hash.Specifically, this part: