automatically call Rollback in Close, resolved #221, #206

This commit is contained in:
Lunny Xiao 2015-03-31 07:03:41 +08:00
parent e2889e5517
commit e4b568f3b3
1 changed files with 7 additions and 3 deletions

View File

@ -45,8 +45,8 @@ type Session struct {
// Method Init reset the session as the init status. // Method Init reset the session as the init status.
func (session *Session) Init() { func (session *Session) Init() {
session.Statement = Statement{Engine: session.Engine}
session.Statement.Init() session.Statement.Init()
session.Statement.Engine = session.Engine
session.IsAutoCommit = true session.IsAutoCommit = true
session.IsCommitedOrRollbacked = false session.IsCommitedOrRollbacked = false
session.IsAutoClose = false session.IsAutoClose = false
@ -67,11 +67,15 @@ func (session *Session) Close() {
} }
if session.db != nil { if session.db != nil {
//session.Engine.Pool.ReleaseDB(session.Engine, session.Db) // When Close be called, if session is a transaction and do not call
session.db = nil // Commit or Rollback, then call Rollback.
if session.Tx != nil && !session.IsCommitedOrRollbacked {
session.Rollback()
}
session.Tx = nil session.Tx = nil
session.stmtCache = nil session.stmtCache = nil
session.Init() session.Init()
session.db = nil
} }
} }