Skip to content

Commit f058035

Browse files
committed
.
1 parent 6a3b6b1 commit f058035

File tree

1 file changed

+12
-51
lines changed

1 file changed

+12
-51
lines changed

charset/charset.go

+12-51
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ package charset
1515

1616
import (
1717
"strings"
18-
"sync/atomic"
1918

2019
"github.com/pingcap/errors"
2120
"github.com/pingcap/parser/mysql"
@@ -25,29 +24,8 @@ import (
2524
var (
2625
ErrUnknownCollation = terror.ClassDDL.NewStd(mysql.ErrUnknownCollation)
2726
ErrCollationCharsetMismatch = terror.ClassDDL.NewStd(mysql.ErrCollationCharsetMismatch)
28-
29-
// enableCharsetFeat is 1 indicate the charset feature is enabled.
30-
enableCharsetFeat = int32(0)
3127
)
3228

33-
func EnableCharsetFeat() {
34-
SetCharsetFratEnabledForTest(true)
35-
}
36-
37-
// SetCharsetFratEnabledForTest set charset feature enabled. Only used in test.
38-
func SetCharsetFratEnabledForTest(flag bool) {
39-
if flag {
40-
atomic.StoreInt32(&enableCharsetFeat, 1)
41-
return
42-
}
43-
atomic.StoreInt32(&enableCharsetFeat, 0)
44-
}
45-
46-
// CharsetFeatEnabled return true if charset feature is enabled.
47-
func CharsetFeatEnabled() bool {
48-
return atomic.LoadInt32(&enableCharsetFeat) == 1
49-
}
50-
5129
// Charset is a charset.
5230
// Now we only support MySQL.
5331
type Charset struct {
@@ -80,11 +58,6 @@ var charsetInfos = map[string]*Charset{
8058
CharsetBin: {CharsetBin, CollationBin, make(map[string]*Collation), "binary", 1},
8159
}
8260

83-
// All the experimental supported charset should be in the following table, only used when charset feature is enable.
84-
var experimentalCharsetInfo = map[string]*Charset{
85-
CharsetGBK: {CharsetGBK, CollationGBK, make(map[string]*Collation), "Chinese Internal Code Specification", 4},
86-
}
87-
8861
// All the names supported collations should be in the following table.
8962
var supportedCollationNames = map[string]struct{}{
9063
CollationUTF8: {},
@@ -101,12 +74,6 @@ func GetSupportedCharsets() []*Charset {
10174
charsets = append(charsets, ch)
10275
}
10376

104-
if CharsetFeatEnabled() {
105-
for _, ch := range experimentalCharsetInfo {
106-
charsets = append(charsets, ch)
107-
}
108-
}
109-
11077
return charsets
11178
}
11279

@@ -154,11 +121,7 @@ func GetCharsetInfo(cs string) (*Charset, error) {
154121
if c, ok := charsetInfos[strings.ToLower(cs)]; ok {
155122
return c, nil
156123
}
157-
if CharsetFeatEnabled() {
158-
if c, ok := experimentalCharsetInfo[strings.ToLower(cs)]; ok {
159-
return c, nil
160-
}
161-
}
124+
162125
return nil, errors.Errorf("Unknown charset %s", cs)
163126
}
164127

@@ -218,6 +181,8 @@ const (
218181
// CollationLatin1 is the default collation for CharsetLatin1.
219182
CollationLatin1 = "latin1_bin"
220183

184+
CollationGBKBin = "gbk_bin"
185+
221186
CharsetARMSCII8 = "armscii8"
222187
CharsetBig5 = "big5"
223188
CharsetBinary = "binary"
@@ -484,16 +449,16 @@ var collations = []*Collation{
484449
// AddCharset adds a new charset.
485450
// Use only when adding a custom charset to the parser.
486451
func AddCharset(c *Charset) {
487-
charsets[c.Name] = c
488-
desc := &Desc{
489-
Name: c.Name,
490-
DefaultCollation: c.DefaultCollation,
491-
Desc: c.Desc,
492-
Maxlen: c.Maxlen,
493-
}
494-
descs = append(descs, desc)
452+
charsetInfos[c.Name] = c
495453
}
496454

455+
// RemoveCharset remove a charset.
456+
// Use only when adding a custom charset to the parser.
457+
func RemoveCharset(c string) {
458+
delete(charsetInfos, c)
459+
}
460+
461+
497462
// AddCollation adds a new collation.
498463
// Use only when adding a custom collation to the parser.
499464
func AddCollation(c *Collation) {
@@ -504,17 +469,13 @@ func AddCollation(c *Collation) {
504469
supportedCollations = append(supportedCollations, c)
505470
}
506471

507-
if charset, ok := charsets[c.CharsetName]; ok {
472+
if charset, ok := charsetInfos[c.CharsetName]; ok {
508473
charset.Collations[c.Name] = c
509474
}
510475
}
511476

512477
// init method always puts to the end of file.
513478
func init() {
514-
for _, c := range charsetInfos {
515-
AddCharset(c)
516-
}
517-
518479
for _, c := range collations {
519480
AddCollation(c)
520481
}

0 commit comments

Comments
 (0)