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.

Commit

Permalink
fix bug when update with setexpr (#1446)
Browse files Browse the repository at this point in the history
  • Loading branch information
lunny authored Oct 2, 2019
1 parent db25dfc commit da95db5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
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

0 comments on commit da95db5

Please sign in to comment.