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 求用stm32f103c6t6在lcd1206上显示Door is open和password:
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类