Skip to content

Commit a5fe3d6

Browse files
authored
ignore empty strings in sets with multiple values (#2759)
1 parent dd8defd commit a5fe3d6

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

enginetest/queries/variable_queries.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,16 @@ var VariableQueries = []ScriptTest{
338338
{"ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,STRICT_ALL_TABLES,STRICT_TRANS_TABLES,TRADITIONAL"},
339339
},
340340
},
341+
{
342+
Name: "set sql_mode variable ignores empty strings",
343+
SetUpScript: []string{
344+
`SET sql_mode = ',,,,STRICT_TRANS_TABLES,,,,,NO_AUTO_VALUE_ON_ZERO,,,,NO_ENGINE_SUBSTITUTION,,,,,,'`,
345+
},
346+
Query: "SELECT @@sql_mode",
347+
Expected: []sql.Row{
348+
{"NO_AUTO_VALUE_ON_ZERO,NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES"},
349+
},
350+
},
341351
{
342352
Name: "show variables renders enums after set",
343353
SetUpScript: []string{

sql/types/set.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,10 @@ func (t SetType) convertStringToBitField(str string) (uint64, error) {
368368
var bitField uint64
369369
vals := strings.Split(str, ",")
370370
for _, val := range vals {
371+
// empty string should hash to 0, so just skip
372+
if val == "" {
373+
continue
374+
}
371375
compareVal := val
372376
if t.collation != sql.Collation_binary {
373377
compareVal = strings.TrimRight(compareVal, " ")

sql/types/set_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ func TestSetConvert(t *testing.T) {
174174
{[]string{"", "one", "two"}, sql.Collation_Default, "", "", false},
175175
{[]string{"", "one", "two"}, sql.Collation_Default, ",one,two", ",one,two", false},
176176
{[]string{"", "one", "two"}, sql.Collation_Default, "one,,two", ",one,two", false},
177+
{[]string{"one", "two"}, sql.Collation_Default, ",one,two", "one,two", false},
177178

178-
{[]string{"one", "two"}, sql.Collation_Default, ",one,two", nil, true},
179179
{[]string{"one", "two"}, sql.Collation_Default, 4, nil, true},
180180
{[]string{"one", "two"}, sql.Collation_Default, "three", nil, true},
181181
{[]string{"one", "two"}, sql.Collation_Default, "one,two,three", nil, true},

0 commit comments

Comments
 (0)