From 632a86f56afebf7fdaeba90e1a20adcac09db00e Mon Sep 17 00:00:00 2001 From: sunvim Date: Thu, 18 Jun 2015 17:41:41 +0800 Subject: [PATCH] =?UTF-8?q?Get=E6=95=B0=E6=8D=AE=E6=97=B6=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E4=BA=86=E5=BC=BA=E5=88=B6=E6=80=A7=E6=8E=92=E4=BB=96?= =?UTF-8?q?=E9=94=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- statement.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/statement.go b/statement.go index 0a8de1ee..c3eb67bd 100644 --- a/statement.go +++ b/statement.go @@ -49,7 +49,7 @@ type Statement struct { GroupByStr string HavingStr string ColumnStr string - selectStr string + selectStr string columnMap map[string]bool useAllCols bool OmitStr string @@ -416,7 +416,7 @@ func buildConditions(engine *Engine, table *core.Table, bean interface{}, var colName string if addedTableName { - colName = engine.Quote(tableName)+"."+engine.Quote(col.Name) + colName = engine.Quote(tableName) + "." + engine.Quote(col.Name) } else { colName = engine.Quote(col.Name) } @@ -428,7 +428,7 @@ func buildConditions(engine *Engine, table *core.Table, bean interface{}, } if col.IsDeleted && !unscoped { // tag "deleted" is enabled - colNames = append(colNames, fmt.Sprintf("(%v IS NULL or %v = '0001-01-01 00:00:00')", + colNames = append(colNames, fmt.Sprintf("(%v IS NULL or %v = '0001-01-01 00:00:00')", colName, colName)) } @@ -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...) } -func (statement *Statement) genSelectSql(columnStr string) (a string) { +func (statement *Statement) genSelectSql(columnStr string) string { /*if statement.GroupByStr != "" { if columnStr == "" { columnStr = statement.Engine.Quote(strings.Replace(statement.GroupByStr, ",", statement.Engine.Quote(","), -1)) } //statement.GroupByStr = columnStr }*/ - var distinct string + var distinct, a string if statement.IsDistinct { 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) } } - - return + //在事务中强制性加入排他锁,不开事务则不起作用 FOR oracle & pg & mysql + a += " FOR UPDATE " + return a } func (statement *Statement) processIdParam() {