Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

这句代码中的事务没有rollback没有问题么? #9

Open
yangqiqi1 opened this issue Nov 7, 2018 · 2 comments
Open

这句代码中的事务没有rollback没有问题么? #9

yangqiqi1 opened this issue Nov 7, 2018 · 2 comments

Comments

@yangqiqi1
Copy link

定义了事务,如果在下面err出错之后进入defer,但是并没有rollback,这样会导致数据库锁吧?
o := orm.NewOrm() err = o.Begin() defer func() { if err == nil { if o.Commit() != nil { if errRollback := o.Rollback(); errRollback != nil { err = errRollback } } } }() if err != nil { return }

@itcloudy
Copy link
Owner

itcloudy commented Nov 7, 2018

对,确实,需要修改

@itcloudy
Copy link
Owner

itcloudy commented Nov 7, 2018

defer func() {
if err == nil {
err = tx.Commit().Error
} else {
err = tx.Rollback().Error
}

}()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants