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
|
// Use QuoteStr quote the string sql
|
||||||
func (engine *Engine) Quote(sql string) string {
|
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()
|
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 + ?"
|
//for update action to like "column = column + ?"
|
||||||
incColumns := session.Statement.getInc()
|
incColumns := session.Statement.getInc()
|
||||||
for k, v := range incColumns {
|
for _, v := range incColumns {
|
||||||
colNames = append(colNames, k+" = "+k+" + ?")
|
colNames = append(colNames, session.Engine.Quote(v.colName)+" = "+session.Engine.Quote(v.colName)+" + ?")
|
||||||
args = append(args, v)
|
args = append(args, v.arg)
|
||||||
}
|
}
|
||||||
var condiColNames []string
|
var condiColNames []string
|
||||||
var condiArgs []interface{}
|
var condiArgs []interface{}
|
||||||
|
|
17
statement.go
17
statement.go
|
@ -15,6 +15,11 @@ type inParam struct {
|
||||||
args []interface{}
|
args []interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type incrParam struct {
|
||||||
|
colName string
|
||||||
|
arg interface{}
|
||||||
|
}
|
||||||
|
|
||||||
// statement save all the sql info for executing SQL
|
// statement save all the sql info for executing SQL
|
||||||
type Statement struct {
|
type Statement struct {
|
||||||
RefTable *core.Table
|
RefTable *core.Table
|
||||||
|
@ -48,7 +53,7 @@ type Statement struct {
|
||||||
checkVersion bool
|
checkVersion bool
|
||||||
mustColumnMap map[string]bool
|
mustColumnMap map[string]bool
|
||||||
inColumns map[string]*inParam
|
inColumns map[string]*inParam
|
||||||
incColumns map[string]interface{}
|
incrColumns map[string]incrParam
|
||||||
}
|
}
|
||||||
|
|
||||||
// init
|
// init
|
||||||
|
@ -79,7 +84,7 @@ func (statement *Statement) Init() {
|
||||||
statement.mustColumnMap = make(map[string]bool)
|
statement.mustColumnMap = make(map[string]bool)
|
||||||
statement.checkVersion = true
|
statement.checkVersion = true
|
||||||
statement.inColumns = make(map[string]*inParam)
|
statement.inColumns = make(map[string]*inParam)
|
||||||
statement.incColumns = make(map[string]interface{}, 0)
|
statement.incrColumns = make(map[string]incrParam)
|
||||||
}
|
}
|
||||||
|
|
||||||
// add the raw sql statement
|
// 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 {
|
func (statement *Statement) Incr(column string, arg ...interface{}) *Statement {
|
||||||
k := strings.ToLower(column)
|
k := strings.ToLower(column)
|
||||||
if len(arg) > 0 {
|
if len(arg) > 0 {
|
||||||
statement.incColumns[k] = arg[0]
|
statement.incrColumns[k] = incrParam{column, arg[0]}
|
||||||
} else {
|
} else {
|
||||||
statement.incColumns[k] = 1
|
statement.incrColumns[k] = incrParam{column, 1}
|
||||||
}
|
}
|
||||||
return statement
|
return statement
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate "Update ... Set column = column + arg" statment
|
// Generate "Update ... Set column = column + arg" statment
|
||||||
func (statement *Statement) getInc() map[string]interface{} {
|
func (statement *Statement) getInc() map[string]incrParam {
|
||||||
return statement.incColumns
|
return statement.incrColumns
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate "Where column IN (?) " statment
|
// Generate "Where column IN (?) " statment
|
||||||
|
|
Loading…
Reference in New Issue