Skip to content
This repository has been archived by the owner on Sep 7, 2021. It is now read-only.
This repository is currently being migrated. It's locked while the migration is in progress.

fix bug when update with setexpr #1446

Merged
merged 1 commit into from
Oct 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions session_update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1390,3 +1390,34 @@ func TestUpdateDeleted(t *testing.T) {
assert.NoError(t, err)
assert.EqualValues(t, 1, cnt)
}

func TestUpdateExprs(t *testing.T) {
assert.NoError(t, prepareEngine())

type UpdateExprs struct {
Id int64
NumIssues int
Name string
}

assertSync(t, new(UpdateExprs))

_, err := testEngine.Insert(&UpdateExprs{
NumIssues: 1,
Name: "lunny",
})
assert.NoError(t, err)

_, err = testEngine.SetExpr("num_issues", "num_issues+1").AllCols().Update(&UpdateExprs{
NumIssues: 3,
Name: "lunny xiao",
})
assert.NoError(t, err)

var ue UpdateExprs
has, err := testEngine.Get(&ue)
assert.NoError(t, err)
assert.True(t, has)
assert.EqualValues(t, 2, ue.NumIssues)
assert.EqualValues(t, "lunny xiao", ue.Name)
}
8 changes: 8 additions & 0 deletions statement.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,14 @@ func (statement *Statement) buildUpdates(bean interface{},
continue
}

if statement.incrColumns.isColExist(col.Name) {
continue
} else if statement.decrColumns.isColExist(col.Name) {
continue
} else if statement.exprColumns.isColExist(col.Name) {
continue
}

fieldValuePtr, err := col.ValueOf(bean)
if err != nil {
engine.logger.Error(err)
Expand Down