diff --git a/enginetest/queries/variable_queries.go b/enginetest/queries/variable_queries.go index 1bf1d52e01..bbf3a2251c 100644 --- a/enginetest/queries/variable_queries.go +++ b/enginetest/queries/variable_queries.go @@ -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{ diff --git a/sql/types/set.go b/sql/types/set.go index 34e6b33956..a9cad68a48 100644 --- a/sql/types/set.go +++ b/sql/types/set.go @@ -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, " ") diff --git a/sql/types/set_test.go b/sql/types/set_test.go index 4241f60d6d..59cde6f575 100644 --- a/sql/types/set_test.go +++ b/sql/types/set_test.go @@ -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},