1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-22 13:40:55 +00:00

add return ErrMultiRows

This commit is contained in:
maxin[马鑫] 2016-04-25 15:51:12 +08:00
parent 9ce6dc4cdf
commit 56dc9bf622
2 changed files with 6 additions and 0 deletions

View File

@ -200,6 +200,10 @@ func (o *querySet) One(container interface{}, cols ...string) error {
if num == 0 { if num == 0 {
return ErrNoRows return ErrNoRows
} }
if num > 1 {
return ErrMultiRows
}
return nil return nil
} }

View File

@ -975,11 +975,13 @@ func TestOne(t *testing.T) {
err = qs.OrderBy("Id").Limit(1).One(&user) err = qs.OrderBy("Id").Limit(1).One(&user)
throwFailNow(t, err) throwFailNow(t, err)
throwFail(t, AssertIs(user.UserName, "slene")) throwFail(t, AssertIs(user.UserName, "slene"))
throwFail(t, AssertNot(err, ErrMultiRows))
user = User{} user = User{}
err = qs.OrderBy("-Id").Limit(100).One(&user) err = qs.OrderBy("-Id").Limit(100).One(&user)
throwFailNow(t, err) throwFailNow(t, err)
throwFail(t, AssertIs(user.UserName, "nobody")) throwFail(t, AssertIs(user.UserName, "nobody"))
throwFail(t, AssertNot(err, ErrMultiRows))
err = qs.Filter("user_name", "nothing").One(&user) err = qs.Filter("user_name", "nothing").One(&user)
throwFail(t, AssertIs(err, ErrNoRows)) throwFail(t, AssertIs(err, ErrNoRows))