err = tx.Raw(chsql).Error
if err != nil {
panic(err)
}
sql在数据库可以成功运行
但是panic : invalid transaction
急盼回复
<a href="/user/fenglangjuxu" title="@fenglangjuxu">@fenglangjuxu</a> 好的 谢谢
#4
更多评论
在panic前面 加个日志 打印出来 当数据为空的时候 err具体是什么 然后对这种err做特殊处理 就是认为是正常的
看了下代码 应该有下面几种
```golang
var (
// ErrRecordNotFound returns a "record not found error". Occurs only when attempting to query the database with a struct; querying with a slice won't return this error
ErrRecordNotFound = errors.New("record not found")
// ErrInvalidSQL occurs when you attempt a query with invalid SQL
ErrInvalidSQL = errors.New("invalid SQL")
// ErrInvalidTransaction occurs when you are trying to `Commit` or `Rollback`
ErrInvalidTransaction = errors.New("no valid transaction")
// ErrCantStartTransaction can't start transaction when you are trying to start one with `Begin`
ErrCantStartTransaction = errors.New("can't start transaction")
// ErrUnaddressable unaddressable value
ErrUnaddressable = errors.New("using unaddressable value")
)
```
#1
你好,感谢回复,打印出来的错误是这样的:
`2021/10/25 16:09:38 invalid transaction; invalid transaction`
是不是就是`no valid transaction`
#2