Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

collation: add new pinyin collation utf8mb4_zh_pinyin_tidb_as_cs #1058

Merged
merged 6 commits into from
Oct 22, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions charset/charset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -421,6 +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_pinyin_tidb_as_cs", false},
}

// init method always puts to the end of file.
Expand All @@ -438,6 +449,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)
Expand All @@ -447,8 +459,4 @@ func init() {
charset.Collations[c.Name] = c
}
}

for id, name := range mysql.Collations {
collationsNameMap[name] = collationsIDMap[int(id)]
}
}