improve code

This commit is contained in:
Lunny Xiao 2019-09-26 00:16:03 +08:00
parent d2c9f9e175
commit 4289572f28
No known key found for this signature in database
GPG Key ID: C3B7C91B632F738A
3 changed files with 3 additions and 14 deletions

View File

@ -100,16 +100,7 @@ func (session *Session) cacheUpdate(table *core.Table, tableName, sqlStr string,
for idx, kv := range kvs {
sps := strings.SplitN(kv, "=", 2)
sps2 := strings.Split(sps[0], ".")
colName := 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
}
colName := unQuote(session.engine, sps2[len(sps2)-1])
if col := table.GetColumn(colName); col != nil {
fieldValue, err := col.ValueOf(bean)

View File

@ -572,10 +572,8 @@ func (statement *Statement) SetExpr(column string, expression interface{}) *Stat
func (statement *Statement) col2NewColsWithQuote(columns ...string) []string {
newColumns := make([]string, 0)
left, right := statement.Engine.Quotes()
quotes := []string{string(left), string(right)}
for _, col := range columns {
newColumns = append(newColumns, statement.Engine.quote(eraseAny(col, quotes...), true))
newColumns = append(newColumns, statement.Engine.quote(col, true))
}
return newColumns
}

View File

@ -243,6 +243,6 @@ func TestCol2NewColsWithQuote(t *testing.T) {
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)
}