solve duplicate log in commit and rollback (#1750)
solve duplicate log in commit and rollback Co-authored-by: Lyi <zhanghong@zuodashi.com> Reviewed-on: https://gitea.com/xorm/xorm/pulls/1750 Reviewed-by: helong zhang <outman99@hotmail.com>
This commit is contained in:
parent
4a6b8c29bf
commit
f39a4cb41c
|
@ -4,12 +4,6 @@
|
||||||
|
|
||||||
package xorm
|
package xorm
|
||||||
|
|
||||||
import (
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"xorm.io/xorm/log"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Begin a transaction
|
// Begin a transaction
|
||||||
func (session *Session) Begin() error {
|
func (session *Session) Begin() error {
|
||||||
if session.isAutoCommit {
|
if session.isAutoCommit {
|
||||||
|
@ -33,24 +27,7 @@ func (session *Session) Rollback() error {
|
||||||
session.isCommitedOrRollbacked = true
|
session.isCommitedOrRollbacked = true
|
||||||
session.isAutoCommit = true
|
session.isAutoCommit = true
|
||||||
|
|
||||||
start := time.Now()
|
return session.tx.Rollback()
|
||||||
needSQL := session.DB().NeedLogSQL(session.ctx)
|
|
||||||
if needSQL {
|
|
||||||
session.engine.logger.BeforeSQL(log.LogContext{
|
|
||||||
Ctx: session.ctx,
|
|
||||||
SQL: "ROLL BACK",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
err := session.tx.Rollback()
|
|
||||||
if needSQL {
|
|
||||||
session.engine.logger.AfterSQL(log.LogContext{
|
|
||||||
Ctx: session.ctx,
|
|
||||||
SQL: "ROLL BACK",
|
|
||||||
ExecuteTime: time.Now().Sub(start),
|
|
||||||
Err: err,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -62,25 +39,7 @@ func (session *Session) Commit() error {
|
||||||
session.isCommitedOrRollbacked = true
|
session.isCommitedOrRollbacked = true
|
||||||
session.isAutoCommit = true
|
session.isAutoCommit = true
|
||||||
|
|
||||||
start := time.Now()
|
if err := session.tx.Commit(); err != nil {
|
||||||
needSQL := session.DB().NeedLogSQL(session.ctx)
|
|
||||||
if needSQL {
|
|
||||||
session.engine.logger.BeforeSQL(log.LogContext{
|
|
||||||
Ctx: session.ctx,
|
|
||||||
SQL: "COMMIT",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
err := session.tx.Commit()
|
|
||||||
if needSQL {
|
|
||||||
session.engine.logger.AfterSQL(log.LogContext{
|
|
||||||
Ctx: session.ctx,
|
|
||||||
SQL: "COMMIT",
|
|
||||||
ExecuteTime: time.Now().Sub(start),
|
|
||||||
Err: err,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue