修改mssql中的datetime类型的处理

This commit is contained in:
wenzi1
2019-08-14 22:44:57 +08:00
parent 8f7363df41
commit c402e17605
2 changed files with 8 additions and 4 deletions

View File

@ -8,6 +8,7 @@ package gdb
import (
"fmt"
"github.com/gogf/gf/os/gtime"
"strings"
"github.com/gogf/gf/encoding/gbinary"
@ -55,6 +56,10 @@ func (bs *dbBase) convertValue(fieldValue []byte, fieldType string) interface{}
case "bool":
return gconv.Bool(fieldValue)
case "datetime":
t, _ := gtime.StrToTime(string(fieldValue))
return t.String()
default:
// 自动识别类型, 以便默认支持更多数据库类型
switch {

View File

@ -565,7 +565,7 @@ func Test_Model_Scan_Mssql(t *testing.T) {
Passport string
Password string
NickName string
CreateTime gtime.Time
CreateTime string
}
user := new(User)
err := msdb.Table(table).Where("id=1").Scan(user)
@ -573,7 +573,7 @@ func Test_Model_Scan_Mssql(t *testing.T) {
gtest.Fatal(err)
}
gtest.Assert(user.NickName, "T1")
gtest.Assert(user.CreateTime.String(), "2018-10-10 00:01:10")
gtest.Assert(user.CreateTime, "2018-10-10 00:01:10")
})
gtest.Case(t, func() {
type User struct {
@ -890,8 +890,7 @@ func Test_Model_Limit_Mssql(t *testing.T) {
gtest.Assert(len(result), 3)
gtest.Assert(result[0]["ID"].Int(), 1)
gtest.Assert(result[0]["NICKNAME"].String(), "T1")
gtest.Assert(result[0]["CREATE_TIME"].GTime().String(), "2018-10-10 00:01:10")
//gtest.Assert(result[0]["CREATE_TIME"].GTime("Y-m-d H:i:s").String(), "2018-10-10 00:01:10")
gtest.Assert(result[0]["CREATE_TIME"].String(), "2018-10-10 00:01:10")
gtest.Assert(result[1]["ID"].Int(), 2)
gtest.Assert(result[1]["NICKNAME"].String(), "T2")