This commit is contained in:
Lunny Xiao 2021-07-17 17:51:59 +08:00
parent c882353b9a
commit 7e70597283
No known key found for this signature in database
GPG Key ID: C3B7C91B632F738A
4 changed files with 5 additions and 52 deletions

View File

@ -19,7 +19,7 @@ func String2Time(s string, originalLocation *time.Location, convertedLocation *t
dt = dt.In(convertedLocation)
return &dt, nil
} else if len(s) == 20 && s[10] == 'T' && s[19] == 'Z' {
dt, err := time.ParseInLocation(time.RFC3339, s, originalLocation)
dt, err := time.ParseInLocation("2006-01-02T15:04:05", s[:19], originalLocation)
if err != nil {
return nil, err
}

View File

@ -15,7 +15,6 @@ import (
"strings"
"time"
"xorm.io/xorm/convert"
"xorm.io/xorm/core"
"xorm.io/xorm/schemas"
)
@ -733,52 +732,6 @@ func (p *mysqlDriver) GenScanResult(colType string) (interface{}, error) {
}
}
func (p *mysqlDriver) Scan(ctx *ScanContext, rows *core.Rows, types []*sql.ColumnType, scanResults ...interface{}) error {
var v2 = make([]interface{}, 0, len(scanResults))
var turnBackIdxes = make([]int, 0, 5)
for i, vv := range scanResults {
switch vv.(type) {
case *time.Time:
v2 = append(v2, &sql.NullString{})
turnBackIdxes = append(turnBackIdxes, i)
case *sql.NullTime:
v2 = append(v2, &sql.NullString{})
turnBackIdxes = append(turnBackIdxes, i)
default:
v2 = append(v2, scanResults[i])
}
}
if err := rows.Scan(v2...); err != nil {
return err
}
for _, i := range turnBackIdxes {
switch t := scanResults[i].(type) {
case *time.Time:
var s = *(v2[i].(*sql.NullString))
if !s.Valid {
break
}
dt, err := convert.String2Time(s.String, ctx.DBLocation, ctx.UserLocation)
if err != nil {
return err
}
*t = *dt
case *sql.NullTime:
var s = *(v2[i].(*sql.NullString))
if !s.Valid {
break
}
dt, err := convert.String2Time(s.String, ctx.DBLocation, ctx.UserLocation)
if err != nil {
return err
}
t.Time = *dt
t.Valid = true
}
}
return nil
}
type mymysqlDriver struct {
mysqlDriver
}

View File

@ -914,7 +914,7 @@ func TestGetTime(t *testing.T) {
assertSync(t, new(GetTimeStruct))
var gts = GetTimeStruct{
CreateTime: time.Now(),
CreateTime: time.Now().In(testEngine.GetTZLocation()),
}
_, err := testEngine.Insert(&gts)
assert.NoError(t, err)

View File

@ -200,14 +200,14 @@ func (engine *Engine) scan(rows *core.Rows, fields []string, types []*sql.Column
var replaced bool
var scanResult interface{}
switch t := v.(type) {
case *big.Float, *time.Time, *sql.NullTime:
scanResult = &sql.NullString{}
replaced = true
case sql.Scanner:
scanResult = t
case convert.Conversion:
scanResult = &sql.RawBytes{}
replaced = true
case *big.Float:
scanResult = &sql.NullString{}
replaced = true
default:
var useNullable = true
if engine.driver.Features().SupportNullable {