vert-x3 / vertx-mysql-postgresql-client

This client is deprecated - use instead
https://github.com/eclipse-vertx/vertx-sql-client
Apache License 2.0
117 stars 59 forks source link

Support for custom charset #149

Closed swordfeng closed 5 years ago

swordfeng commented 5 years ago

The client is creating connections using the default charset mapping, which maps UTF_8 to utf8mb3. However, many DBs use utf8mb4 in order to support 4-byte unicode. Is there a way to customize the charset settings? Maybe passing in a CharsetMapping as a parameter or specifying a charset code.

oshai commented 5 years ago

you can try to set a charset option on the configuration. see DEFAULT_CHARSET here: https://github.com/vert-x3/vertx-mysql-postgresql-client/blob/12a6e6f894/vertx-mysql-postgresql-client-jasync/src/main/java/io/vertx/ext/asyncsql/impl/MYSQLClientImpl.java

Although I haven't tested it myself.

swordfeng commented 5 years ago

That does not work well, actually. From here you can see it always using the default charset mapping and from here you can find only 83, 65, 69 valid. Other values seem not supported.

oshai commented 5 years ago

Yes, I see. I couldn't find the value for the utf8mb4 in mysql docs. what I did find is that this is the default since 8.0.1.

If you have an idea of that value we can try that out.

swordfeng commented 5 years ago

I think the “SHOW COLLATION” statement should give you the id. An example: https://dev.mysql.com/doc/refman/8.0/en/charset-mysql.html

oshai commented 5 years ago

from reading this post. it looks like older utf in mysql was not totally compatible. What I think to do is to change utf8 type in the protocol like this: CharsetUtil.UTF_8 to 224.

I tested it and it works. it might affect legacy databases that do not support this charset.

I will open an issue in jasync-sql itself for this.

oshai commented 5 years ago

@swordfeng - you're welcome to test it with jasync 0.9.50.

swordfeng commented 5 years ago

@oshai Tested and it looks good! I think I can close the issue now. Thanks!