Fix update select clause with before/after expressions, close #5164

This commit is contained in:
Jinzhu 2022-03-18 20:57:33 +08:00
parent d402765f69
commit 540b47571a
1 changed files with 9 additions and 2 deletions

View File

@ -93,7 +93,11 @@ func (db *DB) Select(query interface{}, args ...interface{}) (tx *DB) {
return return
} }
} }
delete(tx.Statement.Clauses, "SELECT")
if clause, ok := tx.Statement.Clauses["SELECT"]; ok {
clause.Expression = nil
tx.Statement.Clauses["SELECT"] = clause
}
case string: case string:
if strings.Count(v, "?") >= len(args) && len(args) > 0 { if strings.Count(v, "?") >= len(args) && len(args) > 0 {
tx.Statement.AddClause(clause.Select{ tx.Statement.AddClause(clause.Select{
@ -123,7 +127,10 @@ func (db *DB) Select(query interface{}, args ...interface{}) (tx *DB) {
} }
} }
delete(tx.Statement.Clauses, "SELECT") if clause, ok := tx.Statement.Clauses["SELECT"]; ok {
clause.Expression = nil
tx.Statement.Clauses["SELECT"] = clause
}
} }
default: default:
tx.AddError(fmt.Errorf("unsupported select args %v %v", query, args)) tx.AddError(fmt.Errorf("unsupported select args %v %v", query, args))