From 4b4568834b54ee13d7ee5920cc930c7fca771d21 Mon Sep 17 00:00:00 2001 From: James Cor Date: Fri, 22 Nov 2024 10:48:05 -0800 Subject: [PATCH 1/2] fix and test --- enginetest/queries/variable_queries.go | 10 ++++++++++ sql/types/set.go | 4 ++++ 2 files changed, 14 insertions(+) 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, " ") From 68cc03e0cd098e7d9edb1e8e3fba330b350c958b Mon Sep 17 00:00:00 2001 From: James Cor Date: Fri, 22 Nov 2024 11:06:13 -0800 Subject: [PATCH 2/2] fixing test --- sql/types/set_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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},