From 2b22fde4872c2c050f6be7773da418cc28d9272e Mon Sep 17 00:00:00 2001 From: jwxiong Date: Fri, 16 Oct 2020 16:44:23 +0800 Subject: [PATCH 1/5] add pinyin collation --- charset/charset.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/charset/charset.go b/charset/charset.go index 1758569ac..106faebb9 100644 --- a/charset/charset.go +++ b/charset/charset.go @@ -421,6 +421,7 @@ var collations = []*Collation{ {246, "utf8mb4", "utf8mb4_unicode_520_ci", false}, {247, "utf8mb4", "utf8mb4_vietnamese_ci", false}, {255, "utf8mb4", "utf8mb4_0900_ai_ci", false}, + {2048, "utf8mb4", "utf8mb4_general_zh_ci", false}, } // init method always puts to the end of file. @@ -438,6 +439,7 @@ func init() { for _, c := range collations { collationsIDMap[c.ID] = c + collationsNameMap[c.Name] = c if _, ok := supportedCollationNames[c.Name]; ok { supportedCollations = append(supportedCollations, c) @@ -447,8 +449,4 @@ func init() { charset.Collations[c.Name] = c } } - - for id, name := range mysql.Collations { - collationsNameMap[name] = collationsIDMap[int(id)] - } } From 6052b03b52f1d424a2166156273b9da65092d0a0 Mon Sep 17 00:00:00 2001 From: jwxiong Date: Mon, 19 Oct 2020 11:17:48 +0800 Subject: [PATCH 2/5] a way to get collation by ID --- charset/charset.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/charset/charset.go b/charset/charset.go index 106faebb9..bc1bce861 100644 --- a/charset/charset.go +++ b/charset/charset.go @@ -177,6 +177,16 @@ func GetCollationByName(name string) (*Collation, error) { return collation, nil } +// GetCollationByID returns collations by given id. +func GetCollationByID(id int) (*Collation, error) { + collation, ok := collationsIDMap[id] + if !ok { + return nil, errors.Errorf("Unknown collation id %d", id) + } + + return collation, nil +} + const ( // CharsetBin is used for marking binary charset. CharsetBin = "binary" From b43688ddff408f08c65036454987738015a263cc Mon Sep 17 00:00:00 2001 From: jwxiong Date: Thu, 22 Oct 2020 17:01:34 +0800 Subject: [PATCH 3/5] rename collation name --- charset/charset.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charset/charset.go b/charset/charset.go index bc1bce861..84ce0255b 100644 --- a/charset/charset.go +++ b/charset/charset.go @@ -431,7 +431,7 @@ var collations = []*Collation{ {246, "utf8mb4", "utf8mb4_unicode_520_ci", false}, {247, "utf8mb4", "utf8mb4_vietnamese_ci", false}, {255, "utf8mb4", "utf8mb4_0900_ai_ci", false}, - {2048, "utf8mb4", "utf8mb4_general_zh_ci", false}, + {2048, "utf8mb4", "utf8mb4_tidb_zh_pinyin_cs", false}, } // init method always puts to the end of file. From 1f94e67fb4c7f30e58dd660426d2168883d10492 Mon Sep 17 00:00:00 2001 From: xiongjiwei Date: Thu, 22 Oct 2020 17:48:05 +0800 Subject: [PATCH 4/5] Update charset/charset.go Co-authored-by: kennytm --- charset/charset.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charset/charset.go b/charset/charset.go index 30d2313bf..3e3aa91e9 100644 --- a/charset/charset.go +++ b/charset/charset.go @@ -431,7 +431,7 @@ var collations = []*Collation{ {246, "utf8mb4", "utf8mb4_unicode_520_ci", false}, {247, "utf8mb4", "utf8mb4_vietnamese_ci", false}, {255, "utf8mb4", "utf8mb4_0900_ai_ci", false}, - {2048, "utf8mb4", "utf8mb4_tidb_zh_pinyin_cs", false}, + {2048, "utf8mb4", "utf8mb4_zh_tidb_pinyin_cs", false}, } // init method always puts to the end of file. From 959ae44b2014c5ab65536d936fbe2dd282ca0e8b Mon Sep 17 00:00:00 2001 From: jwxiong Date: Thu, 22 Oct 2020 18:38:23 +0800 Subject: [PATCH 5/5] rename --- charset/charset.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charset/charset.go b/charset/charset.go index 3e3aa91e9..72816ea93 100644 --- a/charset/charset.go +++ b/charset/charset.go @@ -431,7 +431,7 @@ var collations = []*Collation{ {246, "utf8mb4", "utf8mb4_unicode_520_ci", false}, {247, "utf8mb4", "utf8mb4_vietnamese_ci", false}, {255, "utf8mb4", "utf8mb4_0900_ai_ci", false}, - {2048, "utf8mb4", "utf8mb4_zh_tidb_pinyin_cs", false}, + {2048, "utf8mb4", "utf8mb4_zh_pinyin_tidb_as_cs", false}, } // init method always puts to the end of file.