zim32 / mysql.dart

MySQL client for Dart written in Dart
BSD 3-Clause "New" or "Revised" License
64 stars 17 forks source link

Charset Support for Emoji #37

Closed seceba closed 1 year ago

seceba commented 1 year ago

Greetings,

I get an error when I try to save an emoji to my database or read a saved emoji.

This is because mysql_client uses utf8 by default.

If you use the following option in the connection.dart file in the mysql_client package

 await execute(
      'SET @@collation_connection=$_collation, @@character_set_client=utf8, @@character_set_connection=utf8, @@character_set_results=utf8',
    );

If you change from the above code to the following code, that is, if you change the charsets from utf8 to utf8mb4, the problem will be fixed.

  await execute(
      'SET @@collation_connection=$_collation, @@character_set_client=utf8mb4, @@character_set_connection=utf8mb4, @@character_set_results=utf8mb4',
    ); 

This problem is on the mysql_client side but I think you can fix it by taking a small parameter.

Have a good day.

zim32 commented 1 year ago

HI. I am just wondering is it backwards compatible?

seceba commented 1 year ago

Hi, yes it is compatible, previously we had a database created using utf8mb4 charset and members wrote data.

In this database, some of the data had emojis in some of the data, but when I pulled the data from this database, question marks such as ????? came instead of emojis.

As I said, when I made utf8 utfmb4, these ????? question marks turned into emojis as they should be.

zim32 commented 1 year ago

Ok I will switch default encoding to mb4 variant and add parameter to control this

zim32 commented 1 year ago

Fixed in 0.0.26