前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >golang db.Prepare不支持毫秒。另想办法

golang db.Prepare不支持毫秒。另想办法

作者头像
xiny120
发布2019-06-11 11:13:57
4020
发布2019-06-11 11:13:57
举报
文章被收录于专栏:毛毛v5毛毛v5毛毛v5

用的这个驱动。 _ "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)
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019.05.29 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档