crystal-mysql icon indicating copy to clipboard operation
crystal-mysql copied to clipboard

Configure collation/charset for DB connection

Open Dakad opened this issue 3 years ago • 3 comments

Resolves #46

Context

Allow the configuration of the collation to use during the DB.open connection. Just include into the connection string URI &encoding=utf8mb4_unicode_520_ci The charset is deduced from the encoding. Only the collation with their ID below than 1 byte can be used and some collation are not supported by MySQL. See: https://dev.mysql.com/doc/refman/5.7/en/charset-connection.html#charset-connection-impermissible-client-charset

Dakad avatar Dec 12 '21 16:12 Dakad

If we use a different collation, should the strings sent as arguments be encoded differently? We would need a couple of specs for this change, I fear it could break the support of other collations if there are none.

bcardiff avatar Jan 27 '22 15:01 bcardiff

@Dakad Would it be possible to add some specs for this?

Also note the question in https://github.com/crystal-lang/crystal-mysql/pull/100#issuecomment-1023328125

straight-shoota avatar Sep 18 '22 16:09 straight-shoota

@straight-shoota @bcardiff My bad, I completely forgot about this :disappointed: I will add some specs.

About the question, I'm not sure to fully understand it. I expect the ?encoding= param to be in UTF8 since it's a URI::Params

Dakad avatar Sep 19 '22 18:09 Dakad

I checked with other native driver implementation and it seems they don't do anything to the payload if the collation/charset is different. So extra 👍 on that regard.

bcardiff avatar Dec 17 '22 02:12 bcardiff

All right, then let's merge it 👍

straight-shoota avatar Dec 17 '22 13:12 straight-shoota

Yup. I would drop the unneeded defs I pointed above and merge it. I can take care of it in the following days.

bcardiff avatar Dec 17 '22 13:12 bcardiff

Thanks @Dakad for the contribution and my apologies for the long delay in this PR

bcardiff avatar Dec 18 '22 14:12 bcardiff