Merge c8bed659df
into adadb47c60
This commit is contained in:
commit
14250788eb
16
session.go
16
session.go
|
@ -30,6 +30,7 @@ type Session struct {
|
||||||
IsCommitedOrRollbacked bool
|
IsCommitedOrRollbacked bool
|
||||||
TransType string
|
TransType string
|
||||||
IsAutoClose bool
|
IsAutoClose bool
|
||||||
|
LockRead bool //set sad lock for accepting ro read dirty data
|
||||||
|
|
||||||
// Automatically reset the statement after operations that execute a SQL
|
// Automatically reset the statement after operations that execute a SQL
|
||||||
// query such as Count(), Find(), Get(), ...
|
// query such as Count(), Find(), Get(), ...
|
||||||
|
@ -60,6 +61,7 @@ func (session *Session) Init() {
|
||||||
session.IsCommitedOrRollbacked = false
|
session.IsCommitedOrRollbacked = false
|
||||||
session.IsAutoClose = false
|
session.IsAutoClose = false
|
||||||
session.AutoResetStatement = true
|
session.AutoResetStatement = true
|
||||||
|
session.LockRead = false
|
||||||
|
|
||||||
// !nashtsai! is lazy init better?
|
// !nashtsai! is lazy init better?
|
||||||
session.afterInsertBeans = make(map[interface{}]*[]func(interface{}), 0)
|
session.afterInsertBeans = make(map[interface{}]*[]func(interface{}), 0)
|
||||||
|
@ -104,6 +106,16 @@ func (session *Session) Sql(querystring string, args ...interface{}) *Session {
|
||||||
return session
|
return session
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//set read lock
|
||||||
|
func (session *Session) SetLockRead(lr ...bool) *Session {
|
||||||
|
if 0 == len(lr) {
|
||||||
|
session.LockRead = true
|
||||||
|
} else {
|
||||||
|
session.LockRead = lr[0]
|
||||||
|
}
|
||||||
|
return session
|
||||||
|
}
|
||||||
|
|
||||||
// Method Where provides custom query condition.
|
// Method Where provides custom query condition.
|
||||||
func (session *Session) Where(querystring string, args ...interface{}) *Session {
|
func (session *Session) Where(querystring string, args ...interface{}) *Session {
|
||||||
session.Statement.Where(querystring, args...)
|
session.Statement.Where(querystring, args...)
|
||||||
|
@ -1015,6 +1027,10 @@ func (session *Session) Get(bean interface{}) (bool, error) {
|
||||||
|
|
||||||
if session.Statement.RawSQL == "" {
|
if session.Statement.RawSQL == "" {
|
||||||
sqlStr, args = session.Statement.genGetSql(bean)
|
sqlStr, args = session.Statement.genGetSql(bean)
|
||||||
|
//加入悲观锁 FOR oracle & pg & mysql
|
||||||
|
if session.LockRead {
|
||||||
|
sqlStr += " FOR UPDATE "
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
sqlStr = session.Statement.RawSQL
|
sqlStr = session.Statement.RawSQL
|
||||||
args = session.Statement.RawParams
|
args = session.Statement.RawParams
|
||||||
|
|
|
@ -1172,14 +1172,14 @@ func (statement *Statement) genCountSql(bean interface{}) (string, []interface{}
|
||||||
return statement.genSelectSql(fmt.Sprintf("count(%v)", id)), append(statement.Params, statement.BeanArgs...)
|
return statement.genSelectSql(fmt.Sprintf("count(%v)", id)), append(statement.Params, statement.BeanArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (statement *Statement) genSelectSql(columnStr string) (a string) {
|
func (statement *Statement) genSelectSql(columnStr string) string {
|
||||||
/*if statement.GroupByStr != "" {
|
/*if statement.GroupByStr != "" {
|
||||||
if columnStr == "" {
|
if columnStr == "" {
|
||||||
columnStr = statement.Engine.Quote(strings.Replace(statement.GroupByStr, ",", statement.Engine.Quote(","), -1))
|
columnStr = statement.Engine.Quote(strings.Replace(statement.GroupByStr, ",", statement.Engine.Quote(","), -1))
|
||||||
}
|
}
|
||||||
//statement.GroupByStr = columnStr
|
//statement.GroupByStr = columnStr
|
||||||
}*/
|
}*/
|
||||||
var distinct string
|
var distinct, a string
|
||||||
if statement.IsDistinct {
|
if statement.IsDistinct {
|
||||||
distinct = "DISTINCT "
|
distinct = "DISTINCT "
|
||||||
}
|
}
|
||||||
|
@ -1274,8 +1274,7 @@ func (statement *Statement) genSelectSql(columnStr string) (a string) {
|
||||||
a = fmt.Sprintf("SELECT %v FROM (SELECT %v,ROWNUM RN FROM (%v) at WHERE ROWNUM <= %d) aat WHERE RN > %d", columnStr, columnStr, a, statement.Start+statement.LimitN, statement.Start)
|
a = fmt.Sprintf("SELECT %v FROM (SELECT %v,ROWNUM RN FROM (%v) at WHERE ROWNUM <= %d) aat WHERE RN > %d", columnStr, columnStr, a, statement.Start+statement.LimitN, statement.Start)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return a
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (statement *Statement) processIdParam() {
|
func (statement *Statement) processIdParam() {
|
||||||
|
|
Loading…
Reference in New Issue