THIS IS A TEST INSTANCE ONLY! REPOSITORIES CAN BE DELETED AT ANY TIME!

Browse Source

fix bug when update with setexpr (#1446)

tags/v0.7.9
Lunny Xiao GitHub 1 month ago
parent
commit
da95db5ddc
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 0 deletions
  1. +31
    -0
      session_update_test.go
  2. +8
    -0
      statement.go

+ 31
- 0
session_update_test.go View File

@@ -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
- 0
statement.go View File

@@ -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)


Loading…
Cancel
Save