Closed badrazizi closed 4 years ago
Thanks for reporting, I will take a look
@badrazizi Have you checked your collation/charset in your visualized database client?
Have you checked your collation/charset in your visualized database client?
@BillyYccc sorry i really don't know, i use phpmyadmin that come with xampp.
Mysql configuration
[client]
default-character-set=utf8
[mysqld]
character-set-server = utf8
collation-server = utf8_general_ci
[mysql]
default-character-set=utf8
Can you give some sample rows to reproduce? Are you using text query or preparedQuery? and can you have a try with JDBC MySQL to see if it works in the same way as this client so that we can confirm whether this is a problem
sample rows
Summery | Title | Time | ID | Image | Story | Link |
---|---|---|---|---|---|---|
اعلن مطوري فيجول نوفل World End Economica | الإعلان عن مشروع World End Economica | 2019-11-01 19:00:17.000000 | 650 | /2019/10/World_End_Economica.jpg | اعلن مطوري فيجول نوفل World End Economica | /?p=650 |
yes i use preparedQuery
query = "INSERT INTO `news` (`Title`, `Image`, `Link`, `Summery`, `Story`) VALUES (?, ?, ?, ?, ?)"
params = ArrayTuple(5)
params.addString(obj.getString("title"))
params.addString(obj.getString("image"))
params.addString(obj.getString("link"))
params.addString(obj.getString("summery"))
params.addString(obj.getString("story"))
sqlEngine.preparedQuery(query, params) { saved ->
if(!saved.succeeded()) {
println("Failed to save ${obj.getString("title")}")
} else {
val lastInsertId = saved.result().property(MySQLClient.LAST_INSERTED_ID)
println("Added news with id: $lastInsertId")
}
}
sure i will try JDBC MySQL client
@BillyYccc yes using JDBC MySQL client worked without error and insert new record correctly
gradle
implementation "io.vertx:vertx-jdbc-client:3.8.2"
JDBC Config
private val jdbcClientConfig = JsonObject()
.put("url", "jdbc:${Config.sqlEngine}://${Config.mysqlHost}:${Config.mysqlPort}/${Config.mysqlDatabase}?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC")
.put("user", Config.mysqlUsername)
.put("password", Config.mysqlPassword)
.put("driver_class", "com.mysql.cj.jdbc.Driver")
.put("max_pool_size", 30)
query
query = "INSERT INTO `news` (`Title`, `Image`, `Link`, `Summery`, `Story`) VALUES (?, ?, ?, ?, ?)"
val params2 = JsonArray()
params2.add(obj.getString("title"))
params2.add(obj.getString("image"))
params2.add( obj.getString("link"))
params2.add(obj.getString("summery"))
params2.add(story)
sqlClient.queryWithParams(query, params2) { ar ->
if(!ar.succeeded()) {
println("Failed to save ${obj.getString("title")}")
}
}
result
Summery | Title | Time | ID | Image | Story | Link |
---|---|---|---|---|---|---|
اعلن مطوري فيجول نوفل World End Economica | الإعلان عن مشروع World End Economica | 2019-11-01 19:00:17.000000 | 650 | /2019/10/World_End_Economica.jpg | اعلن مطوري فيجول نوفل World End Economica | /?p=650 |
@BillyYccc any progress, i have not heard from in almost 3 days.
can you try with adding useServerPrepStmts=true
to the connection properties of the JDBC url so that the jdbc client uses server-side prepared queries and check that again? The MySQL JDBC client will use a client-side prepared statement by default which is different from reactive mysql client so the comparison does not make sense.
yes it does insert new record correctly with useServerPrepStmts=true
jdbc config
private val jdbcClientConfig = JsonObject()
.put("url", "jdbc:${Config.sqlEngine}://${Config.mysqlHost}:${Config.mysqlPort}/${Config.mysqlDatabase}?useUnicode=true&useServerPrepStmts=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC")
.put("user", Config.mysqlUsername)
.put("password", Config.mysqlPassword)
.put("driver_class", "com.mysql.cj.jdbc.Driver")
.put("max_pool_size", 30)
I have given another try in https://github.com/BillyYccc/reactive-mysql-client-issue444 but still could not reproduce the problem. I debug the network packets for both JDBC and reactive MySQL client and what they send to server is identical.
I notice you did not configure the characterEncoding
property in JDBC, can you try with my reproducer and try again?
with or without characterEncoding
jdbc still insert new record correctly, i have created a reproducer please give it a test here
@BillyYccc please test the reproducer i post above.
I did more experiements but I could not reproduce the problem with using MySQLWorkbench and other clients.
I start MySQL using docker in my reproducer project and here is my server charset config
SHOW VARIABLES LIKE '%character%'
Variable_name | Value
-- | --
character_set_client | utf8mb4
character_set_connection | utf8mb4
character_set_database | utf8
character_set_filesystem | binary
character_set_results | utf8mb4
character_set_server | utf8
character_set_system | utf8
character_sets_dir | /usr/share/mysql/charsets/
can you try retrieving those rows inserted by reactive-mysql-client
via JDBC or tools other than phpmyadmin
(like MySQLWorkbench) like what I do in my reproducer and compare the results?
MySQLWorkbench
SHOW VARIABLES LIKE '%character%'
character_set_client | utf8mb4 |
---|---|
character_set_connection | utf8mb4 |
character_set_database | utf8 |
character_set_filesystem | binary |
character_set_results | utf8mb4 |
character_set_server | utf8 |
character_set_system | utf8 |
character_sets_dir | C:\xampp\mysql\share\charsets\ |
Result from MySQLWorkbench
result from JDBC
[{
"Summery": "كشفت مجلة شونين جمب عن إعلان مهم يخص مانجا Jujutsu Kaisen للمانجاكا جيجي أكوتامي سيتم الكشف عنه في العدد القادم من المجلة، كما تم الكشف كذلك عن حجز نطاق خاص بعنوان jujutsukaisen.jp ما يزيد من احتمالية حصول المانجا على أنمي خصوصًا و أن المجلد السابع من المانجا قد تم إصداره …",
"Title": "حجز نطاق وإعلان مهم قادم لمانجا Jujutsu Kaisen، هل ستحصل المانجا على أنمي؟",
"Time": "2019-11-14 19:00:04.000000"
}, {
"Summery": "تم الكشف عن عرض تشويقي للأنمي المأخوذ من لعبة الهواتف الذكية I★CHU والقادم بعنوان I★CHU Étoile Stage وكذلك عن طاقم العمل بالإضافة إلى الصورة بالأعلى. طاقم العمل الاستديو: Lay-duce. المخرج: هيتوشي نانبا (Golden Kamuy). منسق القصة: يوشيمي ناريتا. مصمم الشخصيات: مينا أوساوا (Given,) قصة اللعبة تدور في أكادمية تسمى Etoile …",
"Title": "عرض والكشف عن طاقم العمل لأنمي I★CHU",
"Time": "2019-11-14 19:00:07.000000"
}, {
"Summery": "???? ???? ????? ??? ?? ????? ??? ??? ????? Jujutsu Kaisen ????????? ???? ??????? ???? ????? ??? ?? ????? ?????? ?? ??????? ??? ?? ????? ???? ?? ??? ???? ??? ?????? jujutsukaisen.jp ?? ???? ?? ???????? ???? ??????? ??? ???? ?????? ? ?? ?????? ?????? ?? ??????? ?? ?? ?????? ?",
"Title": "??? ???? ?????? ??? ???? ?????? Jujutsu Kaisen? ?? ????? ??????? ??? ?????",
"Time": "2019-11-14 17:08:19.371199"
}, {
"Summery": "??? ?????? ???? ????? ???? ??????? ?? ???? ?cole des Nouvelles Images. ????? ??? ??46 ????? ????? ????? ?? 150 ??????? ????? ???? ???? ??? ???? ???????? ?? ??? ?????? ????? ????????.",
"Title": "??? ???? ????: Hors Piste",
"Time": "2019-11-14 17:08:19.503090"
}, {
"Summery": "???? ???? ?????? ?? ????? 23 ??? ????????? ??? ????? (???? Boku dake ga Inai Machi) ????? ????? ????? ?????? Mizutamari ni Ukabu Shima ???????? ?? ????? 24 ?? 26 ??????. ????? ????? ?????? ?? 44 ???? ???????? ??? ???????? ????? ? ???? ??? ???? ??????. ???? ?????: ???? ?????? ?",
"Title": "???? Boku dake ga Inai Machi ???? ????? ?????",
"Time": "2019-11-14 17:08:19.530617"
}, {
"Summery": "??? ?????? ?????? ?? ??? ???? ????? Kishibe Rohan wa Ugokanai ??????? ????? ?? ??????? ????????? ???? ????? ?? 6 ??? ???????? ?? 8 ??????. ?????? ?? ??????? ?? ????? ??????? ? ?????? ?????? 16 ?????? At a Confessional (????????) ??????? 10 ?????? The Run (?????) ? ???? ??? ????? ?",
"Title": "??? ???? ?????? ???? ????? ??????? ?????? ??????? ?? Kishibe Rohan wa Ugokanai ?? ???? 2020",
"Time": "2019-11-14 17:08:19.607746"
}, {
"Summery": "?? ????? ?? ??? ?????? ?????? ??????? ?? ???? ??????? ?????? I?CHU ??????? ?????? I?CHU ?toile Stage ????? ?? ???? ????? ???????? ??? ?????? ???????. ???? ????? ????????: Lay-duce. ??????: ?????? ????? (Golden Kamuy). ???? ?????: ?????? ??????. ???? ????????: ???? ?????? (Given,) ??? ?????? ???? ?? ??????? ???? Etoile ?",
"Title": "??? ?????? ?? ???? ????? ????? I?CHU",
"Time": "2019-11-14 17:08:19.619506"
}, {
"Summery": "???? ?? ????? ????? ?????? ??? ?????? ?????? ?????? ?????? ??? ?????? ?????? ?????? ?? ?????? ??? ???? ?????? ???????? ????? ?? ??? Dragon Ball Super Broly ???? ?? ????? ???? ??? ??????? ?????? ???? ???? ??? ???? ????? ?? ?????? ??? ??? ?? ???????? ???? ???? ?????.",
"Title": "????? ?????? ????? ???????? ????? (DBS) ????? Dragon Ball FighterZ",
"Time": "2019-11-14 17:08:21.533535"
}, {
"Summery": "",
"Title": "????: GIANTS ????? League of Legends",
"Time": "2019-11-14 17:08:21.643565"
}, {
"Summery": "??? ?????? ?????? ????? Yahari Ore no Seishun ?? ????? ??????? ?????? ?????? ???????? ??? ?????? ??????? ????? ????? ???? ?? ????? 2020. ??? ?? ????? ?? ????? ?????? ?????? ???? Yahari Ore no Seishun Love Comedy wa Machigatteiru: Kan ?????? 12 ????. ??? ?? ??????? ??? ?? ?????? ????? ?",
"Title": "???? ?????? ?? ????? ??????? ?????? ?????? ?? ???? Yahari Ore no Seishun ?????? ???? ????? ?? ?????",
"Time": "2019-11-14 17:08:21.908703"
}
]
please note that retrieving data with reactive-mysql-client
is correct the data is displayed correctly the issue is in saving new record
@badrazizi thanks for the clues I see where the problem locates now.
can you by the way check what your default charset is by calling java.nio.charset.Charset.defaultCharset().displayName()
it print windows-1252
i just got it working thanks to your comment by setting jvm default charset to utf8
System.setProperty("file.encoding", "UTF-8")
val charset = Charset::class.java.getDeclaredField("defaultCharset")
charset.isAccessible = true
charset.set(null,null)
but actually does not solve the issue since MySQLPool#pool
does not respect MySQLConnectOptions()#setCharset
configuration, also JDBC is working because i think is set to utf8 by default, or am i misunderstanding the code.
Yes setting a default charset to UTF-8 seems to be a work around for now.
the charset
and collation
options are configured at the connection level but not really have and effects on charset for encoding, currently the encoding value is encoded in the default charset and I believe we need to improve this, I have posted an issue in https://github.com/eclipse-vertx/vertx-sql-client/issues/447.
I am using version 3.8.2 and having some issues with utf8 string appears as question mark (?) in the database when inserting new record, but it's display old record correctly (inserted using phpmyadmin).
this how it's appeared.
here how i init MySQLPool
mysql variables
table news
mysql create table
aslo changed the type from text to varchar with same result
from
to