From e4b568f3b35d18789067531c628fcae9ef860f0e Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 31 Mar 2015 07:03:41 +0800 Subject: [PATCH] automatically call Rollback in Close, resolved #221, #206 --- session.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/session.go b/session.go index 0d11d99f..069bf075 100644 --- a/session.go +++ b/session.go @@ -45,8 +45,8 @@ type Session struct { // Method Init reset the session as the init status. func (session *Session) Init() { - session.Statement = Statement{Engine: session.Engine} session.Statement.Init() + session.Statement.Engine = session.Engine session.IsAutoCommit = true session.IsCommitedOrRollbacked = false session.IsAutoClose = false @@ -67,11 +67,15 @@ func (session *Session) Close() { } if session.db != nil { - //session.Engine.Pool.ReleaseDB(session.Engine, session.Db) - session.db = nil + // When Close be called, if session is a transaction and do not call + // Commit or Rollback, then call Rollback. + if session.Tx != nil && !session.IsCommitedOrRollbacked { + session.Rollback() + } session.Tx = nil session.stmtCache = nil session.Init() + session.db = nil } }