diff --git a/session_update.go b/session_update.go index 792fb574..a1d25bab 100644 --- a/session_update.go +++ b/session_update.go @@ -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", top, session.Engine.Quote(session.Statement.TableName()), diff --git a/session_update_test.go b/session_update_test.go index ef4c1e70..d4bf437e 100644 --- a/session_update_test.go +++ b/session_update_test.go @@ -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()) +}