From 4289572f28b73aecbf43f6f643d18181c7c5e24d Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Thu, 26 Sep 2019 00:16:03 +0800 Subject: [PATCH] improve code --- session_update.go | 11 +---------- statement.go | 4 +--- statement_test.go | 2 +- 3 files changed, 3 insertions(+), 14 deletions(-) diff --git a/session_update.go b/session_update.go index 3993eb15..e899e7b6 100644 --- a/session_update.go +++ b/session_update.go @@ -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) diff --git a/statement.go b/statement.go index 1b51fe54..16b35d31 100644 --- a/statement.go +++ b/statement.go @@ -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 } diff --git a/statement_test.go b/statement_test.go index 832deca4..84cad131 100644 --- a/statement_test.go +++ b/statement_test.go @@ -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) }