improve update error when no conent to be updated (#648)
This commit is contained in:
parent
774f83c1bc
commit
305eb27bcf
|
@ -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()),
|
||||||
|
|
|
@ -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())
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue