From 4b4568834b54ee13d7ee5920cc930c7fca771d21 Mon Sep 17 00:00:00 2001 From: James Cor Date: Fri, 22 Nov 2024 10:48:05 -0800 Subject: [PATCH] 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, " ")