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?

图片转代码服务由CSDN问答提供 功能建议

嗨,我正在使用数据库/ sql程序包,例如,我有这样的文件:

  var DeletePermissionStmt * sql.Stmt 
DeletePermissionStmt,err = database.Prepare(`DELETE FROMPermission WHEREPermission_id = $ 1`)
if err!= nil {
 log.Errorf(“无法准备删除 权限声明:%s“,err.Error())
} 
transaction,err:= database.Begin()//假定先前已定义postgres数据库
if err!= nil {
 log.WithFields(logFields)  .Errorf(“无法启动事务:%s”,err.Error())
 
 
返回err 
} 
_,err:= transaction.Stmt(DeletePermissionStmt).Exec(permission_id)
    
 
 

我成功完成了我想做的事情,除了我想记录所使用的确切查询,并且如果我在postgres中运行它,我将拥有相同的查询 结果 反正有吗?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题