用的这个驱动。
_ "github.com/go-sql-driver/mysql"
如果是如下代码,时间有毫秒,就有错误提示:
2019/05/29 12:05:04 apis_public.go:444:
select
a.[Id], a.[CreateDate],a.[PublisherId],a.[NickName],a.[FileSize],a.[Followed],
a.[Readed],a.[FilePath], b.[STitle],a.[CreateDate],a.[Encryptioned],a.[FileName]
from [hds12204021_db].[dbo].[Web2019_historylist] a, [hds12204021_db].[dbo].[Web2019_roomlist] b
where a.roomid = ? and a.Deleted = 0 and a.roomid=b.id and a.[CreateDate] > ?
order by a.CreateDate desc
2019/05/29 12:05:04 apis_public.go:452: ServeSrs sql stmt.Query error 发生意外。 (应用程序在当前操作中使用了错误类型的值。) 1 20 {2b7e7bfc-2730-49fe-ba43-a3e1043fcc13}
第二个问号通配符,如果提供"2019-02-02 12:12:12" 就正常,如果提供 "2019-02-02 12:12:12.123" 就提示 应用程序在当前操作中使用了错误类型的值 .切记。。。。
可以改成如下方式必面:
sqlstr := `
select
a.[Id], a.[CreateDate],a.[PublisherId],a.[NickName],a.[FileSize],a.[Followed],
a.[Readed],a.[FilePath], b.[STitle],a.[CreateDate],a.[Encryptioned],a.[FileName]
from [hds12204021_db].[dbo].[Web2019_historylist] a, [hds12204021_db].[dbo].[Web2019_roomlist] b
where a.roomid = ? and a.Deleted = 0 and a.roomid=b.id and a.[CreateDate] > CONVERT(datetime,'` + CreateDate + `')
order by a.CreateDate desc
`
log.Println(sqlstr)
stmt1, err0 := db.Prepare(sqlstr)
有疑问加站长微信联系(非本文作者)