* fix #1075 and replace #1076 * fix bug when session resue
This commit is contained in:
parent
5271caa592
commit
6fe3ab6075
|
@ -74,6 +74,13 @@ func (eg *EngineGroup) Close() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewSession returned a group session
|
||||||
|
func (eg *EngineGroup) NewSession() *Session {
|
||||||
|
sess := eg.Engine.NewSession()
|
||||||
|
sess.sessionType = groupSession
|
||||||
|
return sess
|
||||||
|
}
|
||||||
|
|
||||||
// Master returns the master engine
|
// Master returns the master engine
|
||||||
func (eg *EngineGroup) Master() *Engine {
|
func (eg *EngineGroup) Master() *Engine {
|
||||||
return eg.Engine
|
return eg.Engine
|
||||||
|
|
11
session.go
11
session.go
|
@ -18,6 +18,13 @@ import (
|
||||||
"github.com/go-xorm/core"
|
"github.com/go-xorm/core"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type sessionType int
|
||||||
|
|
||||||
|
const (
|
||||||
|
engineSession sessionType = iota
|
||||||
|
groupSession
|
||||||
|
)
|
||||||
|
|
||||||
// Session keep a pointer to sql.DB and provides all execution of all
|
// Session keep a pointer to sql.DB and provides all execution of all
|
||||||
// kind of database operations.
|
// kind of database operations.
|
||||||
type Session struct {
|
type Session struct {
|
||||||
|
@ -52,8 +59,8 @@ type Session struct {
|
||||||
lastSQL string
|
lastSQL string
|
||||||
lastSQLArgs []interface{}
|
lastSQLArgs []interface{}
|
||||||
|
|
||||||
err error
|
ctx context.Context
|
||||||
ctx context.Context
|
sessionType sessionType
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clone copy all the session's content and return a new session
|
// Clone copy all the session's content and return a new session
|
||||||
|
|
|
@ -49,7 +49,7 @@ func (session *Session) queryRows(sqlStr string, args ...interface{}) (*core.Row
|
||||||
|
|
||||||
if session.isAutoCommit {
|
if session.isAutoCommit {
|
||||||
var db *core.DB
|
var db *core.DB
|
||||||
if session.engine.engineGroup != nil {
|
if session.sessionType == groupSession {
|
||||||
db = session.engine.engineGroup.Slave().DB()
|
db = session.engine.engineGroup.Slave().DB()
|
||||||
} else {
|
} else {
|
||||||
db = session.DB()
|
db = session.DB()
|
||||||
|
|
Loading…
Reference in New Issue