Skip to content
This repository was archived by the owner on Sep 7, 2021. It is now read-only.
This repository is currently being migrated. It's locked while the migration is in progress.

Commit ecc286a

Browse files
committed
improve code
1 parent 0b941d9 commit ecc286a

File tree

3 files changed

+3
-14
lines changed

3 files changed

+3
-14
lines changed

session_update.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,7 @@ func (session *Session) cacheUpdate(table *core.Table, tableName, sqlStr string,
100100
for idx, kv := range kvs {
101101
sps := strings.SplitN(kv, "=", 2)
102102
sps2 := strings.Split(sps[0], ".")
103-
colName := sps2[len(sps2)-1]
104-
// treat quote prefix, suffix and '`' as quotes
105-
left, right := session.engine.Quotes()
106-
quotes := []string{string(left), string(right)}
107-
if strings.ContainsAny(colName, strings.Join(quotes, "")) {
108-
colName = strings.TrimSpace(eraseAny(colName, quotes...))
109-
} else {
110-
session.engine.logger.Debug("[cacheUpdate] cannot find column", tableName, colName)
111-
return ErrCacheFailed
112-
}
103+
colName := unQuote(session.engine, sps2[len(sps2)-1])
113104

114105
if col := table.GetColumn(colName); col != nil {
115106
fieldValue, err := col.ValueOf(bean)

statement.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -560,10 +560,8 @@ func (statement *Statement) SetExpr(column string, expression interface{}) *Stat
560560

561561
func (statement *Statement) col2NewColsWithQuote(columns ...string) []string {
562562
newColumns := make([]string, 0)
563-
left, right := statement.Engine.Quotes()
564-
quotes := []string{string(left), string(right)}
565563
for _, col := range columns {
566-
newColumns = append(newColumns, statement.Engine.quote(eraseAny(col, quotes...), true))
564+
newColumns = append(newColumns, statement.Engine.quote(col, true))
567565
}
568566
return newColumns
569567
}

statement_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,6 @@ func TestCol2NewColsWithQuote(t *testing.T) {
243243

244244
statement := createTestStatement()
245245

246-
quotedCols := statement.col2NewColsWithQuote(cols...)
246+
quotedCols := quoteJoin(statement.Engine, cols)
247247
assert.EqualValues(t, []string{statement.Engine.Quote("f1", true), statement.Engine.Quote("f2", true), statement.Engine.Quote("t3.f3", true)}, quotedCols)
248248
}

0 commit comments

Comments
 (0)