perl DBIx sqlite {sqlite_unicode=>1}?

发布于 2024-10-17 19:22:19 字数 695 浏览 6 评论 0原文

如果连接到 MySQL 时:

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

连接强制为 utf8;

连接到SQLite

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

连接似乎不是utf8;

目的是消除在获取数据时必须使用decode(): 来自:

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

至:

$cycle->type

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

逆蝶 2024-10-24 19:22:19

如果你用这个连接怎么办:

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

也许 connect() 正在寻找选项 hash-ref 作为参数四,而没有意识到 SQLite 不需要用户名和密码参数。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文