duanboshe0001 2016-09-19 07:25
浏览 35
已采纳

在GO中使用transaction.Stmt(sqlstatement).Exec(parameter)时是否可以记录最终查询?

Hi I am using database/sql package, and for example I have this:

var DeletePermissionStmt *sql.Stmt
DeletePermissionStmt, err = database.Prepare(`DELETE FROM permission WHERE permission_id=$1`)
if err != nil {
    log.Errorf("can't prepare delete permission statement: %s", err.Error())
}
transaction, err := database.Begin()  // assume postgres database is defined previously
if err != nil {
    log.WithFields(logFields).Errorf("can't start transaction: %s", err.Error())


    return err
}
_, err := transaction.Stmt(DeletePermissionStmt).Exec(permission_id)

I am succeeding in doing what I want to do except that I want to log the exact query that is used and that if I run it in postgres I will have the same result Is there anyway to do it?

  • 写回答

1条回答 默认 最新

  • drz49609 2016-09-19 12:06
    关注

    Transaction uses standard SQL i.e. BEGIN / START TRANSACTION, COMMIT, ROLLBACK. However, prepared statements are specific to database server, e.g.

    Taking log of exact query with database/sql will be difficult (or impossible). Query logging depends on implementation of the driver, for example https://github.com/jackc/pgx supports logging, but https://github.com/lib/pq doesn't support.

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

报告相同问题?

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 虚心请教几个问题,小生先有礼了
  • ¥30 截图中的mathematics程序转换成matlab