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.

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

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?