Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import java.math.BigInteger;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
Expand Down Expand Up @@ -179,7 +180,7 @@ public static void encodeBinary(DataType dataType, Object value, Charset charset
case VARSTRING:
default:
if (value instanceof JsonObject || value instanceof JsonArray) {
binaryEncodeJson(value, buffer);
binaryEncodeJson(value, buffer, charset);
return;
} else if (value == Tuple.JSON_NULL) {
// we have to make JSON literal null send as a STRING data type
Expand Down Expand Up @@ -467,7 +468,11 @@ private static void binaryEncodeDatetime(LocalDateTime value, ByteBuf buffer) {
}
}

private static void binaryEncodeJson(Object value, ByteBuf buffer) {
private static void binaryEncodeJson(Object value, ByteBuf buffer, Charset charset) {
if (!StandardCharsets.UTF_8.equals(charset)) {
BufferUtils.writeLengthEncodedString(buffer, Json.encode(value), charset);
return;
}
ByteBuf tmp = buffer.alloc().buffer();
try {
Json.encodeTo(value, new ByteBufOutputStream(tmp));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
package io.vertx.tests.mysqlclient;

import io.vertx.core.Vertx;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.unit.TestContext;
import io.vertx.ext.unit.junit.VertxUnitRunner;
import io.vertx.mysqlclient.MySQLConnectOptions;
Expand Down Expand Up @@ -95,6 +96,20 @@ public void testConnectionCharset(TestContext ctx) {
}));
}

@Test
public void testJsonParameterWithConnectionCollation(TestContext ctx) {
MySQLConnectOptions connectOptions = options.setCollation("gbk_chinese_ci");
MySQLConnection.connect(vertx, connectOptions).onComplete(ctx.asyncAssertSuccess(conn -> {
conn
.preparedQuery("SELECT JSON_UNQUOTE(JSON_EXTRACT(CAST(? AS JSON), '$.city')) AS city")
.execute(Tuple.of(new JsonObject().put("city", "\u5317\u4EAC")))
.onComplete(ctx.asyncAssertSuccess(res -> {
ctx.assertEquals("\u5317\u4EAC", res.iterator().next().getString("city"));
conn.close();
}));
}));
}

@Test
public void testTableCollationBinary(TestContext ctx) {
testBinary(ctx, PREPARE_TESTING_TABLE_DATA);
Expand Down