分享
golang db.Prepare不支持毫秒。另想办法
毛毛v5 · · 1773 次点击 · · 开始浏览这是一个创建于 的文章,其中的信息可能已经有所发展或是发生改变。
用的这个驱动。
_ "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)
有疑问加站长微信联系(非本文作者)
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
关注微信1773 次点击
添加一条新回复
(您需要 后才能回复 没有账号 ?)
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码` - 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传
收入到我管理的专栏 新建专栏
用的这个驱动。
_ "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)