Get数据时增加了强制性排他锁

This commit is contained in:
sunvim 2015-06-18 17:41:41 +08:00
parent 72ee356344
commit 632a86f56a
1 changed files with 8 additions and 7 deletions

View File

@ -49,7 +49,7 @@ type Statement struct {
GroupByStr string GroupByStr string
HavingStr string HavingStr string
ColumnStr string ColumnStr string
selectStr string selectStr string
columnMap map[string]bool columnMap map[string]bool
useAllCols bool useAllCols bool
OmitStr string OmitStr string
@ -416,7 +416,7 @@ func buildConditions(engine *Engine, table *core.Table, bean interface{},
var colName string var colName string
if addedTableName { if addedTableName {
colName = engine.Quote(tableName)+"."+engine.Quote(col.Name) colName = engine.Quote(tableName) + "." + engine.Quote(col.Name)
} else { } else {
colName = engine.Quote(col.Name) colName = engine.Quote(col.Name)
} }
@ -1139,14 +1139,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 "
} }
@ -1241,8 +1241,9 @@ 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)
} }
} }
//在事务中强制性加入排他锁,不开事务则不起作用 FOR oracle & pg & mysql
return a += " FOR UPDATE "
return a
} }
func (statement *Statement) processIdParam() { func (statement *Statement) processIdParam() {