du5739 2019-08-27 00:06
浏览 85
已采纳

go-sql-driver / mysql-将float64插入mariadb(双列)会提供不受支持的类型func()float64,即func

I am new to Go I just started learning it a few days ago for the concurrency :-). I have a different library that returns a time.Duration type, which has Seconds, a float64 precision value I'd like to use and store in a database.

Here are relevant bits and pieces to what I'm trying to accomplish:

type pResp struct {
    address string
    rtt     time.Duration
    sent    int
    recv    int
}

stmt, err := db.Prepare("insert pings set domain = ?, packet_rtt = ?, packets_sent = ?, packets_recv = ?")
res, err := stmt.Exec(r.address, r.rtt.Seconds, r.sent, r.recv)

This is the error I get:

2019/08/26 19:57:35 sql: converting argument $2 type: unsupported type func() float64, a func
Process exiting with code: 0

The column in MySQL is set to double, which should be 64 bits... I am not sure where I am going wrong here. Is this a limitation of the library I am using? Thanks.

  • 写回答

1条回答 默认 最新

  • dragonhong641016 2019-08-27 00:22
    关注

    It appears that you are passing a first class function func() float64 instead of an actual float64 primitive. The source of this function looks to be r.rtt.Seconds, which should be invoked as r.rtt.Seconds(). See Duration.Seconds.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Oracle触发器记录修改前后的字段值
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器