From 0671607d29438b2ba840661a8748c48885770a9e Mon Sep 17 00:00:00 2001 From: liyadi Date: Mon, 30 Nov 2020 09:35:11 +0800 Subject: [PATCH] =?UTF-8?q?select=20case=E8=AF=AD=E6=B3=95=E9=94=99?= =?UTF-8?q?=E8=AF=AF,=E9=80=A0=E6=88=90time=E5=AD=97=E6=AE=B5=E7=B2=BE?= =?UTF-8?q?=E5=BA=A6time(1),time(3),time(5)=E5=80=BC=E4=B8=BA00:00:00?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- replication/row_event.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/replication/row_event.go b/replication/row_event.go index 5cdfb825b..7875ac5cb 100644 --- a/replication/row_event.go +++ b/replication/row_event.go @@ -1419,11 +1419,10 @@ func decodeTime2(data []byte, dec uint16) (string, int, error) { intPart := int64(0) frac := int64(0) switch dec { - case 1: - case 2: + case 1, 2: intPart = int64(BFixedLengthInt(data[0:3])) - TIMEF_INT_OFS frac = int64(data[3]) - if intPart < 0 && frac > 0 { + if intPart < 0 && frac != 0 { /* Negative values are stored with reverse fractional part order, for binary sort compatibility. @@ -1445,11 +1444,10 @@ func decodeTime2(data []byte, dec uint16) (string, int, error) { frac -= 0x100 /* -(0x100 - frac) */ } tmp = intPart<<24 + frac*10000 - case 3: - case 4: + case 3, 4: intPart = int64(BFixedLengthInt(data[0:3])) - TIMEF_INT_OFS frac = int64(binary.BigEndian.Uint16(data[3:5])) - if intPart < 0 && frac > 0 { + if intPart < 0 && frac != 0 { /* Fix reverse fractional part order: "0x10000 - frac". See comments for FSP=1 and FSP=2 above. @@ -1459,9 +1457,9 @@ func decodeTime2(data []byte, dec uint16) (string, int, error) { } tmp = intPart<<24 + frac*100 - case 5: - case 6: + case 5, 6: tmp = int64(BFixedLengthInt(data[0:6])) - TIMEF_OFS + return timeFormat(tmp, n) default: intPart = int64(BFixedLengthInt(data[0:3])) - TIMEF_INT_OFS tmp = intPart << 24 @@ -1471,6 +1469,10 @@ func decodeTime2(data []byte, dec uint16) (string, int, error) { return "00:00:00", n, nil } + return timeFormat(tmp, n) +} + +func timeFormat(tmp int64, n int) (string, int, error) { hms := int64(0) sign := "" if tmp < 0 {