crystal-mysql
crystal-mysql copied to clipboard
Configure collation/charset for DB connection
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
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.
@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 @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
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.
All right, then let's merge it 👍
Yup. I would drop the unneeded defs I pointed above and merge it. I can take care of it in the following days.
Thanks @Dakad for the contribution and my apologies for the long delay in this PR