Skip to content

Commit a0090e5

Browse files
committed
fix(AbstractRowsEventDataDeserializer): add microsecond precision for datetime/timestamp
1 parent 3f1bc55 commit a0090e5

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/main/java/com/github/shyiko/mysql/binlog/event/deserialization/AbstractRowsEventDataDeserializer.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import java.math.BigDecimal;
2525
import java.util.BitSet;
2626
import java.util.Calendar;
27-
import java.util.Date;
2827
import java.util.Map;
2928
import java.util.TimeZone;
3029

@@ -312,7 +311,7 @@ protected Serializable deserializeTimestampV2(int meta, ByteArrayInputStream inp
312311
if (deserializeDateAndTimeAsLong) {
313312
return castTimestamp(timestamp, fsp);
314313
}
315-
return new java.sql.Timestamp(timestamp);
314+
return convertLongTimestamptWithFSP(timestamp, fsp);
316315
}
317316

318317
protected Serializable deserializeDatetime(ByteArrayInputStream inputStream) throws IOException {
@@ -321,7 +320,7 @@ protected Serializable deserializeDatetime(ByteArrayInputStream inputStream) thr
321320
if (deserializeDateAndTimeAsLong) {
322321
return castTimestamp(timestamp, 0);
323322
}
324-
return timestamp != null ? new java.util.Date(timestamp) : null;
323+
return timestamp != null ? new java.sql.Timestamp(timestamp) : null;
325324
}
326325

327326
protected Serializable deserializeDatetimeV2(int meta, ByteArrayInputStream inputStream) throws IOException {
@@ -354,7 +353,14 @@ protected Serializable deserializeDatetimeV2(int meta, ByteArrayInputStream inpu
354353
if (deserializeDateAndTimeAsLong) {
355354
return castTimestamp(timestamp, fsp);
356355
}
357-
return timestamp != null ? new java.util.Date(timestamp) : null;
356+
357+
return timestamp != null ? convertLongTimestamptWithFSP(timestamp, fsp) : null;
358+
}
359+
360+
private java.sql.Timestamp convertLongTimestamptWithFSP(Long timestamp, int fsp) {
361+
java.sql.Timestamp ts = new java.sql.Timestamp(timestamp);
362+
ts.setNanos(fsp * 1000);
363+
return ts;
358364
}
359365

360366
protected Serializable deserializeYear(ByteArrayInputStream inputStream) throws IOException {

0 commit comments

Comments
 (0)