perl DBIx sqlite {sqlite_unicode=>1}?

旧巷老猫 提交于 2019-11-30 18:39:54

问题


If connecting to MySQL with:

my $schema = MyDatabase::Main->connect("dbi:mysql:database=$database;host=$host",'root','', {mysql_enable_utf8 => 1});

The connection is forced to utf8;

Connect to SQLite:

my $schema = MyDatabase::Main->connect('dbi:SQLite:data/sample.db', {sqlite_unicode => 1});

The connection seems not to be in utf8;

The purpose is to eliminate having to use decode() while fetching data: from:

Mojo::ByteStream->new($cycle->type)->decode('utf-8')

to:

$cycle->type

Thanks


回答1:


What if you connect with this:

my $schema = MyDatabase::Main->connect(
    'dbi:SQLite:data/sample.db',
    '', # empty username
    '', # empty password
    {sqlite_unicode => 1}
);

Maybe connect() is looking for the options hash-ref as argument four without realizing that SQLite doesn't need the username and password arguments.



来源:https://stackoverflow.com/questions/5000080/perl-dbix-sqlite-sqlite-unicode-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!