mirror of
https://gitee.com/johng/gf
synced 2026-06-06 16:21:40 +08:00
修改mssql中的datetime类型的处理
This commit is contained in:
@ -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 {
|
||||
|
||||
@ -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")
|
||||
|
||||
Reference in New Issue
Block a user