Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ignore empty strings in sets with multiple values #2759

Merged
merged 2 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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