Return error if Delete has no any condition
This commit is contained in:
parent
5113f5d35b
commit
8294b99ea6
1
error.go
1
error.go
|
@ -10,4 +10,5 @@ var (
|
|||
ErrUnSupportedType error = errors.New("unsupported type error")
|
||||
ErrNotExist error = errors.New("not exist error")
|
||||
ErrCacheFailed error = errors.New("cache failed")
|
||||
ErrNeedDeletedCond error = errors.New("delete need at least one condition")
|
||||
)
|
||||
|
|
17
session.go
17
session.go
|
@ -1718,20 +1718,19 @@ func (session *Session) Delete(bean interface{}) (int64, error) {
|
|||
|
||||
var condition = ""
|
||||
if session.Statement.WhereStr != "" {
|
||||
condition = fmt.Sprintf("WHERE %v", session.Statement.WhereStr)
|
||||
condition = session.Statement.WhereStr
|
||||
if len(colNames) > 0 {
|
||||
condition += " and "
|
||||
condition += strings.Join(colNames, " and ")
|
||||
condition += " and " + strings.Join(colNames, " and ")
|
||||
}
|
||||
} else {
|
||||
condition = "WHERE " + strings.Join(colNames, " and ")
|
||||
condition = strings.Join(colNames, " and ")
|
||||
}
|
||||
if len(condition) == 0 {
|
||||
return 0, ErrNeedDeletedCond
|
||||
}
|
||||
|
||||
sql := fmt.Sprintf("DELETE FROM %v%v%v %v",
|
||||
session.Engine.QuoteStr(),
|
||||
session.Statement.TableName(),
|
||||
session.Engine.QuoteStr(),
|
||||
condition)
|
||||
sql := fmt.Sprintf("DELETE FROM %v WHERE %v",
|
||||
session.Engine.Quote(session.Statement.TableName()), condition)
|
||||
|
||||
args = append(session.Statement.Params, args...)
|
||||
|
||||
|
|
Loading…
Reference in New Issue