CurtTilmes / perl6-dbmysql

DB::MySQL
2 stars 3 forks source link

Malformed UTF-8 #7

Open mikkelstb opened 5 years ago

mikkelstb commented 5 years ago

When trying to print out data after successfully have run a query. I get the following error whenever i try to print text that contains Nordic vocals (ie øæå). I can loop over rows in a for loop, after having run query().arrays.

On a different server, the same code with the same query, works just fine. I even copied over the libmariadb file that the server used. Both server and my workstation runs linux. But still with the same problem. I assume that the problem is specific to my own workstation, though I wonder if there is a workaround?

Malformed UTF-8 at line 1 col 2 in sub mysql-value-Str at /home/x/rakudo/share/perl6/site/sources/715B7B691EFB5DDF0C875852F7F436F293969520 (DB::MySQL::Converter) line 14 in method bind-value at /home/x/rakudo/share/perl6/site/sources/715B7B691EFB5DDF0C875852F7F436F293969520 (DB::MySQL::Converter) line 253 in code at /home/x/rakudo/share/perl6/site/sources/507086ECAA98656966E41BC1EE8B998728F2C615 (DB::MySQL::Result) line 71 in method row at /home/x/rakudo/share/perl6/site/sources/507086ECAA98656966E41BC1EE8B998728F2C615 (DB::MySQL::Result) line 69 in method pull-one at /home/x/rakudo/share/perl6/site/sources/51F6397FB5D02B2A0E15A62EC3ACF47669DBF3DC (DB::Result) line 7

bbkr commented 5 years ago

Do you have collations set up properly on all servers? Check if show variables like '%collation%' returns utf8 or utf8mb4 formats like this:

mysql> show variables like '%collation%';
+----------------------+--------------------+
| Variable_name        | Value              |
+----------------------+--------------------+
| collation_connection | utf8mb4_general_ci |
| collation_database   | utf8mb4_general_ci |
| collation_server     | utf8mb4_general_ci |
+----------------------+--------------------+
3 rows in set (0.00 sec)
CurtTilmes commented 5 years ago

Thanks @bbkr. Right now the string decoding assumes UTF-8. If you have a different encoding on your server, it probably won't work right.

You may be able to play games with the MySQL cast() or convert() functions. Instead of select foo, say select convert(foo using utf8) as foo.