Skip to content
Merged
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 @@ -704,7 +704,7 @@ private static String textDecodeText(int collationId, ByteBuf buffer, int index,

private static LocalDate textDecodeDate(int collationId, ByteBuf buffer, int index, int length) {
Charset charset = MySQLCollation.getJavaCharsetByCollationId(collationId);
CharSequence cs = buffer.toString(index, length, charset);
String cs = buffer.toString(index, length, charset);
if (cs.equals("0000-00-00")) {
// Invalid date will be converted to zero
return null;
Expand Down Expand Up @@ -743,8 +743,8 @@ private static Duration textDecodeTime(int collationId, ByteBuf buffer, int inde

private static LocalDateTime textDecodeDateTime(int collationId, ByteBuf buffer, int index, int length) {
Charset charset = MySQLCollation.getJavaCharsetByCollationId(collationId);
CharSequence cs = buffer.toString(index, length, charset);
if (cs.equals("0000-00-00 00:00:00")) {
String cs = buffer.toString(index, length, charset);
if (cs.startsWith("0000-00-00 00:00:00")) {
// Invalid datetime will be converted to zero
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,21 @@ public void testDecodeTimestamp(TestContext ctx) {
testTextDecodeGenericWithTable(ctx, "test_timestamp", LocalDateTime.of(2000, 1, 1, 10, 20, 30));
}

@Test
public void testDecodeDatetimeWithFractionalSecondsEmpty(TestContext ctx) {
MySQLConnection.connect(vertx, options).onComplete(ctx.asyncAssertSuccess(conn -> {
conn
.query("SET SESSION sql_mode = ''")
.execute()
.compose(v -> conn.query("SELECT CAST('0000-00-00 00:00:00' AS DATETIME(6)) test_datetime").execute())
.onComplete(ctx.asyncAssertSuccess(result -> {
ctx.assertEquals(1, result.size());
ctx.assertNull(result.iterator().next().getValue("test_datetime"));
conn.close();
}));
}));
}

@Override
protected <T> void testDecodeGeneric(TestContext ctx, String data, String dataType, String columnName, T expected) {
testDecodeGeneric(ctx, data, dataType, row -> {
Expand Down
Loading