improve update error when no conent to be updated (#648)

This commit is contained in:
Lunny Xiao 2017-07-21 16:42:23 +08:00 committed by GitHub
parent 774f83c1bc
commit 305eb27bcf
2 changed files with 24 additions and 0 deletions

View File

@ -330,6 +330,10 @@ func (session *Session) Update(bean interface{}, condiBean ...interface{}) (int6
} }
} }
if len(colNames) <= 0 {
return 0, errors.New("No content found to be updated")
}
sqlStr = fmt.Sprintf("UPDATE %v%v SET %v %v", sqlStr = fmt.Sprintf("UPDATE %v%v SET %v %v",
top, top,
session.Engine.Quote(session.Statement.TableName()), session.Engine.Quote(session.Statement.TableName()),

View File

@ -1093,3 +1093,23 @@ func TestBool(t *testing.T) {
} }
} }
} }
func TestNoUpdate(t *testing.T) {
assert.NoError(t, prepareEngine())
type NoUpdate struct {
Id int64
Content string
}
assertSync(t, new(NoUpdate))
_, err := testEngine.Insert(&NoUpdate{
Content: "test",
})
assert.NoError(t, err)
_, err = testEngine.Id(1).Update(&NoUpdate{})
assert.Error(t, err)
assert.EqualValues(t, "No content found to be updated", err.Error())
}