Skip to content

Commit

Permalink
fix bug of inserting quoted field (#96)
Browse files Browse the repository at this point in the history
* fix bug of inserting quoted field

* CI just run go test

* remove travis CI
  • Loading branch information
caibirdme authored Aug 14, 2020
1 parent 25636c8 commit 7f57111
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
3 changes: 0 additions & 3 deletions .travis.yml

This file was deleted.

14 changes: 14 additions & 0 deletions builder/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1241,3 +1241,17 @@ func TestNotLike_1(t *testing.T) {
ass.Equal(expectVals, vals)
}
}

func TestFixBug_insert_quote_field(t *testing.T) {
cond, vals, err := BuildInsert("tb", []map[string]interface{}{
{
"id": 1,
"`order`": 2,
"`id`": 3, // I know this is forbidden, but just for test
},
})
ass := assert.New(t)
ass.NoError(err)
ass.Equal("INSERT INTO tb (`id`,`order`,id) VALUES (?,?,?)", cond)
ass.Equal([]interface{}{3,2,1}, vals)
}
2 changes: 1 addition & 1 deletion builder/dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ func buildInsert(table string, setMap []map[string]interface{}, insertType inser
for _, mapItem := range setMap {
sets = append(sets, placeholder)
for _, field := range fields {
val, ok := mapItem[strings.Trim(field, "`")]
val, ok := mapItem[field]
if !ok {
return "", nil, errInsertDataNotMatch
}
Expand Down

0 comments on commit 7f57111

Please sign in to comment.