4

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

Makoto
  • 104,088
  • 27
  • 192
  • 230
Weiyan
  • 1,116
  • 3
  • 14
  • 25

1 Answers1

9

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.

mu is too short
  • 426,620
  • 70
  • 833
  • 800
  • i almost didn't click to this thread because the subject line was unclear...but that's what made me click. i'm glad i did, and although comments aren't typically for thank yous, i wanted to extend my thanks. this unicode/wide character stuff is a pain and this saved me from a huge headache. – Jarett Lloyd Dec 06 '19 at 21:03