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条)

报告相同问题?

悬赏问题

  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python