ddl: fix a bug that creating a table with set column don't handle collation correctly (#17905)
Signed-off-by: wjhuang2016 <huangwenjun1997@gmail.com>
This commit is contained in:
@ -760,15 +760,16 @@ func setSetDefaultValue(v types.Datum, col *table.Column) (string, error) {
|
||||
return str, nil
|
||||
}
|
||||
|
||||
ctor := collate.GetCollator(col.Collate)
|
||||
valMap := make(map[string]struct{}, len(col.Elems))
|
||||
dVals := strings.Split(strings.ToLower(str), ",")
|
||||
dVals := strings.Split(str, ",")
|
||||
for _, dv := range dVals {
|
||||
valMap[dv] = struct{}{}
|
||||
valMap[string(ctor.Key(dv))] = struct{}{}
|
||||
}
|
||||
var existCnt int
|
||||
for dv := range valMap {
|
||||
for i := range col.Elems {
|
||||
e := strings.ToLower(col.Elems[i])
|
||||
e := string(ctor.Key(col.Elems[i]))
|
||||
if e == dv {
|
||||
existCnt++
|
||||
break
|
||||
|
||||
@ -6619,3 +6619,15 @@ func (s *testIntegrationSuite) TestIssue17287(c *C) {
|
||||
tk.MustQuery("execute stmt7 using @val1;").Check(testkit.Rows("1589873945"))
|
||||
tk.MustQuery("execute stmt7 using @val2;").Check(testkit.Rows("1589873946"))
|
||||
}
|
||||
|
||||
func (s *testIntegrationSerialSuite) TestIssue17891(c *C) {
|
||||
collate.SetNewCollationEnabledForTest(true)
|
||||
defer collate.SetNewCollationEnabledForTest(false)
|
||||
|
||||
tk := testkit.NewTestKit(c, s.store)
|
||||
tk.MustExec("use test")
|
||||
tk.MustExec("drop table if exists t")
|
||||
tk.MustExec("create table t(id int, value set ('a','b','c') charset utf8mb4 collate utf8mb4_bin default 'a,b ');")
|
||||
tk.MustExec("drop table t")
|
||||
tk.MustExec("create table test(id int, value set ('a','b','c') charset utf8mb4 collate utf8mb4_general_ci default 'a,B ,C');")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user