mirror of
https://github.com/alibaba/canal.git
synced 2026-11-04 00:30:15 +08:00
* fix the issue that client-adapter.rdb module loses precision when converting microsencond time * fix the issue that client-adapter.rdb module loses precision when converting to java.sql.Time or java.sql.Timestamp * fix the issue that client-adapter.rdb module loses precision when converting to java.sql.Time or java.sql.Timestamp
This commit is contained in:
@@ -12,6 +12,7 @@ import java.io.StringReader;
|
||||
import java.math.BigDecimal;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.sql.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
@@ -220,11 +221,16 @@ public class SyncUtil {
|
||||
pstmt.setTime(i, new java.sql.Time(((java.util.Date) value).getTime()));
|
||||
} else if (value instanceof String) {
|
||||
String v = (String) value;
|
||||
java.util.Date date = Util.parseDate(v);
|
||||
if (date != null) {
|
||||
pstmt.setTime(i, new Time(date.getTime()));
|
||||
} else {
|
||||
pstmt.setNull(i, type);
|
||||
if(Util.isAccuracyOverSecond(v)) {
|
||||
//the java.sql.time doesn't support for even millisecond, only setObject works here.
|
||||
pstmt.setObject(i, v);
|
||||
}else {
|
||||
java.util.Date date = Util.parseDate(v);
|
||||
if (date != null) {
|
||||
pstmt.setTime(i, new Time(date.getTime()));
|
||||
} else {
|
||||
pstmt.setNull(i, type);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
pstmt.setNull(i, type);
|
||||
@@ -238,11 +244,22 @@ public class SyncUtil {
|
||||
} else if (value instanceof String) {
|
||||
String v = (String) value;
|
||||
if (!v.startsWith("0000-00-00")) {
|
||||
java.util.Date date = Util.parseDate(v);
|
||||
if (date != null) {
|
||||
pstmt.setTimestamp(i, new Timestamp(date.getTime()));
|
||||
} else {
|
||||
pstmt.setNull(i, type);
|
||||
if(Util.isAccuracyOverMillisecond(v)){
|
||||
//convert to ISO-8601 standard format, with up to nanoseconds (9 digits) precision
|
||||
LocalDateTime isoDatetime = Util.parseISOLocalDateTime(v);
|
||||
if (isoDatetime != null) {
|
||||
pstmt.setTimestamp(i, Timestamp.valueOf(isoDatetime));
|
||||
} else {
|
||||
//if can't convert, set to null
|
||||
pstmt.setNull(i, type);
|
||||
}
|
||||
}else {
|
||||
java.util.Date date = Util.parseDate(v);
|
||||
if (date != null) {
|
||||
pstmt.setTimestamp(i, new Timestamp(date.getTime()));
|
||||
} else {
|
||||
pstmt.setNull(i, type);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
pstmt.setObject(i, value);
|
||||
|
||||
Reference in New Issue
Block a user