dongquexi1990 2019-06-21 14:33
浏览 31
已采纳

寻找一种在Golang MySQL中查看插值查询的方法

So, I have a reasonably complicated query which I am trying to debug, but for a simple example let's say I have something like this:

q := "SELECT id FROM users WHERE timestamp > ? AND timestamp < ?"

I will do a Query() on this the usual way, e.g.

db.Query(q, 1546300800,1561127488)

And I would like to log/println/whatever (for debugging) the interpolated query, to end up with

SELECT id FROM users WHERE timestamp > 1546300800 AND timestamp < 1561127488

Wondering if anyone has a trick for me here.

  • 写回答

2条回答 默认 最新

  • dpr81047 2019-06-21 19:45
    关注

    Based on @mkopriva's comments,

    Not in Go as it does not do the interpolation, both the query string and the argument values are sent to the db server, which does the interpolation. So if the db server doesn't provide such a feature then you're out of luck. Alternatively you could try searching for a 3rd party package that does the interpolation, however if you find one keep in mind that to be accurate it needs to keep up with the target server's version, if it doesn't do that you may see logs that don't match the actual query being executed

    I cannot accomplish this using tooling, as go never has the interpolated query. Sticking to spitting out the non-interpolated query along with the pile of arguments.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 如何通过代码传输视频到亚马逊平台
  • ¥15 php查询mysql数据库并显示至下拉列表中
  • ¥15 freertos下使用外部中断失效
  • ¥15 输入的char字符转为int类型,不是对应的ascall码,如何才能使之转换为对应ascall码?或者使输入的char字符可以正常与其他字符比较?
  • ¥15 devserver配置完 启动服务 无法访问static上的资源
  • ¥15 解决websocket跟c#客户端通信
  • ¥30 Python调用dll文件输出Nan重置dll状态
  • ¥15 浮动div的高度控制问题。
  • ¥66 换电脑后应用程序报错
  • ¥50 array数据同步问题