Skip to content

Commit 4030c73

Browse files
committed
修复ftime sql序列化问题
1 parent 212197c commit 4030c73

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

types/ftime/sql.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,27 @@ package ftime
22

33
import (
44
"database/sql/driver"
5+
"errors"
56
)
67

78
// Scan 实现sql的反序列化
8-
func (t Time) Scan(value interface{}) {
9-
switch UsedFormatType {
10-
case TIMESTAMP:
11-
value = t.timestamp()
12-
case TEXT:
13-
value = t.formatText()
9+
func (t *Time) Scan(value interface{}) error {
10+
if t == nil {
11+
return nil
12+
}
13+
14+
switch v := value.(type) {
15+
case int64:
16+
return t.parseTSInt64(v)
17+
case string:
18+
return t.parseTS(v)
1419
default:
15-
value = t.timestamp()
20+
return errors.New("unsupport type")
1621
}
1722
}
1823

1924
// Value 实现sql的序列化
20-
func (t *Time) Value() (driver.Value, error) {
25+
func (t Time) Value() (driver.Value, error) {
2126
switch UsedFormatType {
2227
case TIMESTAMP:
2328
return t.timestamp(), nil

types/ftime/time.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ func (t Time) formatText() []byte {
100100
func (t Time) timestamp() int64 {
101101
var ts int64
102102

103+
if t.T().IsZero() {
104+
return 0
105+
}
106+
103107
switch UsedTimestampLength {
104108
case Length10:
105109
ts = time.Time(t).Unix()

0 commit comments

Comments
 (0)