improve code
This commit is contained in:
parent
d2c9f9e175
commit
4289572f28
|
@ -100,16 +100,7 @@ func (session *Session) cacheUpdate(table *core.Table, tableName, sqlStr string,
|
||||||
for idx, kv := range kvs {
|
for idx, kv := range kvs {
|
||||||
sps := strings.SplitN(kv, "=", 2)
|
sps := strings.SplitN(kv, "=", 2)
|
||||||
sps2 := strings.Split(sps[0], ".")
|
sps2 := strings.Split(sps[0], ".")
|
||||||
colName := sps2[len(sps2)-1]
|
colName := unQuote(session.engine, sps2[len(sps2)-1])
|
||||||
// treat quote prefix, suffix and '`' as quotes
|
|
||||||
left, right := session.engine.Quotes()
|
|
||||||
quotes := []string{string(left), string(right)}
|
|
||||||
if strings.ContainsAny(colName, strings.Join(quotes, "")) {
|
|
||||||
colName = strings.TrimSpace(eraseAny(colName, quotes...))
|
|
||||||
} else {
|
|
||||||
session.engine.logger.Debug("[cacheUpdate] cannot find column", tableName, colName)
|
|
||||||
return ErrCacheFailed
|
|
||||||
}
|
|
||||||
|
|
||||||
if col := table.GetColumn(colName); col != nil {
|
if col := table.GetColumn(colName); col != nil {
|
||||||
fieldValue, err := col.ValueOf(bean)
|
fieldValue, err := col.ValueOf(bean)
|
||||||
|
|
|
@ -572,10 +572,8 @@ func (statement *Statement) SetExpr(column string, expression interface{}) *Stat
|
||||||
|
|
||||||
func (statement *Statement) col2NewColsWithQuote(columns ...string) []string {
|
func (statement *Statement) col2NewColsWithQuote(columns ...string) []string {
|
||||||
newColumns := make([]string, 0)
|
newColumns := make([]string, 0)
|
||||||
left, right := statement.Engine.Quotes()
|
|
||||||
quotes := []string{string(left), string(right)}
|
|
||||||
for _, col := range columns {
|
for _, col := range columns {
|
||||||
newColumns = append(newColumns, statement.Engine.quote(eraseAny(col, quotes...), true))
|
newColumns = append(newColumns, statement.Engine.quote(col, true))
|
||||||
}
|
}
|
||||||
return newColumns
|
return newColumns
|
||||||
}
|
}
|
||||||
|
|
|
@ -243,6 +243,6 @@ func TestCol2NewColsWithQuote(t *testing.T) {
|
||||||
|
|
||||||
statement := createTestStatement()
|
statement := createTestStatement()
|
||||||
|
|
||||||
quotedCols := statement.col2NewColsWithQuote(cols...)
|
quotedCols := quoteJoin(statement.Engine, cols)
|
||||||
assert.EqualValues(t, []string{statement.Engine.Quote("f1", true), statement.Engine.Quote("f2", true), statement.Engine.Quote("t3.f3", true)}, quotedCols)
|
assert.EqualValues(t, []string{statement.Engine.Quote("f1", true), statement.Engine.Quote("f2", true), statement.Engine.Quote("t3.f3", true)}, quotedCols)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue