bug fixed for Incr
This commit is contained in:
parent
9a6458134a
commit
82e73d6002
|
@ -75,6 +75,12 @@ func (engine *Engine) QuoteStr() string {
|
|||
|
||||
// Use QuoteStr quote the string sql
|
||||
func (engine *Engine) Quote(sql string) string {
|
||||
if len(sql) == 0 {
|
||||
return sql
|
||||
}
|
||||
if string(sql[0]) == engine.dialect.QuoteStr() || sql[0] == '`' {
|
||||
return sql
|
||||
}
|
||||
return engine.dialect.QuoteStr() + sql + engine.dialect.QuoteStr()
|
||||
}
|
||||
|
||||
|
|
|
@ -2956,9 +2956,9 @@ func (session *Session) Update(bean interface{}, condiBean ...interface{}) (int6
|
|||
|
||||
//for update action to like "column = column + ?"
|
||||
incColumns := session.Statement.getInc()
|
||||
for k, v := range incColumns {
|
||||
colNames = append(colNames, k+" = "+k+" + ?")
|
||||
args = append(args, v)
|
||||
for _, v := range incColumns {
|
||||
colNames = append(colNames, session.Engine.Quote(v.colName)+" = "+session.Engine.Quote(v.colName)+" + ?")
|
||||
args = append(args, v.arg)
|
||||
}
|
||||
var condiColNames []string
|
||||
var condiArgs []interface{}
|
||||
|
|
17
statement.go
17
statement.go
|
@ -15,6 +15,11 @@ type inParam struct {
|
|||
args []interface{}
|
||||
}
|
||||
|
||||
type incrParam struct {
|
||||
colName string
|
||||
arg interface{}
|
||||
}
|
||||
|
||||
// statement save all the sql info for executing SQL
|
||||
type Statement struct {
|
||||
RefTable *core.Table
|
||||
|
@ -48,7 +53,7 @@ type Statement struct {
|
|||
checkVersion bool
|
||||
mustColumnMap map[string]bool
|
||||
inColumns map[string]*inParam
|
||||
incColumns map[string]interface{}
|
||||
incrColumns map[string]incrParam
|
||||
}
|
||||
|
||||
// init
|
||||
|
@ -79,7 +84,7 @@ func (statement *Statement) Init() {
|
|||
statement.mustColumnMap = make(map[string]bool)
|
||||
statement.checkVersion = true
|
||||
statement.inColumns = make(map[string]*inParam)
|
||||
statement.incColumns = make(map[string]interface{}, 0)
|
||||
statement.incrColumns = make(map[string]incrParam)
|
||||
}
|
||||
|
||||
// add the raw sql statement
|
||||
|
@ -464,16 +469,16 @@ func (statement *Statement) Id(id interface{}) *Statement {
|
|||
func (statement *Statement) Incr(column string, arg ...interface{}) *Statement {
|
||||
k := strings.ToLower(column)
|
||||
if len(arg) > 0 {
|
||||
statement.incColumns[k] = arg[0]
|
||||
statement.incrColumns[k] = incrParam{column, arg[0]}
|
||||
} else {
|
||||
statement.incColumns[k] = 1
|
||||
statement.incrColumns[k] = incrParam{column, 1}
|
||||
}
|
||||
return statement
|
||||
}
|
||||
|
||||
// Generate "Update ... Set column = column + arg" statment
|
||||
func (statement *Statement) getInc() map[string]interface{} {
|
||||
return statement.incColumns
|
||||
func (statement *Statement) getInc() map[string]incrParam {
|
||||
return statement.incrColumns
|
||||
}
|
||||
|
||||
// Generate "Where column IN (?) " statment
|
||||
|
|
Loading…
Reference in New Issue