Skip to content

Commit

Permalink
ignore empty strings in sets with multiple values (#2759)
Browse files Browse the repository at this point in the history
  • Loading branch information
jycor authored Nov 22, 2024
1 parent dd8defd commit a5fe3d6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
10 changes: 10 additions & 0 deletions enginetest/queries/variable_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,16 @@ var VariableQueries = []ScriptTest{
{"ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,STRICT_ALL_TABLES,STRICT_TRANS_TABLES,TRADITIONAL"},
},
},
{
Name: "set sql_mode variable ignores empty strings",
SetUpScript: []string{
`SET sql_mode = ',,,,STRICT_TRANS_TABLES,,,,,NO_AUTO_VALUE_ON_ZERO,,,,NO_ENGINE_SUBSTITUTION,,,,,,'`,
},
Query: "SELECT @@sql_mode",
Expected: []sql.Row{
{"NO_AUTO_VALUE_ON_ZERO,NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES"},
},
},
{
Name: "show variables renders enums after set",
SetUpScript: []string{
Expand Down
4 changes: 4 additions & 0 deletions sql/types/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,10 @@ func (t SetType) convertStringToBitField(str string) (uint64, error) {
var bitField uint64
vals := strings.Split(str, ",")
for _, val := range vals {
// empty string should hash to 0, so just skip
if val == "" {
continue
}
compareVal := val
if t.collation != sql.Collation_binary {
compareVal = strings.TrimRight(compareVal, " ")
Expand Down
2 changes: 1 addition & 1 deletion sql/types/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ func TestSetConvert(t *testing.T) {
{[]string{"", "one", "two"}, sql.Collation_Default, "", "", false},
{[]string{"", "one", "two"}, sql.Collation_Default, ",one,two", ",one,two", false},
{[]string{"", "one", "two"}, sql.Collation_Default, "one,,two", ",one,two", false},
{[]string{"one", "two"}, sql.Collation_Default, ",one,two", "one,two", false},

{[]string{"one", "two"}, sql.Collation_Default, ",one,two", nil, true},
{[]string{"one", "two"}, sql.Collation_Default, 4, nil, true},
{[]string{"one", "two"}, sql.Collation_Default, "three", nil, true},
{[]string{"one", "two"}, sql.Collation_Default, "one,two,three", nil, true},
Expand Down

0 comments on commit a5fe3d6

Please sign in to comment.