@@ -15,7 +15,6 @@ package charset
15
15
16
16
import (
17
17
"strings"
18
- "sync/atomic"
19
18
20
19
"github.com/pingcap/errors"
21
20
"github.com/pingcap/parser/mysql"
@@ -25,29 +24,8 @@ import (
25
24
var (
26
25
ErrUnknownCollation = terror .ClassDDL .NewStd (mysql .ErrUnknownCollation )
27
26
ErrCollationCharsetMismatch = terror .ClassDDL .NewStd (mysql .ErrCollationCharsetMismatch )
28
-
29
- // enableCharsetFeat is 1 indicate the charset feature is enabled.
30
- enableCharsetFeat = int32 (0 )
31
27
)
32
28
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
-
51
29
// Charset is a charset.
52
30
// Now we only support MySQL.
53
31
type Charset struct {
@@ -80,11 +58,6 @@ var charsetInfos = map[string]*Charset{
80
58
CharsetBin : {CharsetBin , CollationBin , make (map [string ]* Collation ), "binary" , 1 },
81
59
}
82
60
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
-
88
61
// All the names supported collations should be in the following table.
89
62
var supportedCollationNames = map [string ]struct {}{
90
63
CollationUTF8 : {},
@@ -101,12 +74,6 @@ func GetSupportedCharsets() []*Charset {
101
74
charsets = append (charsets , ch )
102
75
}
103
76
104
- if CharsetFeatEnabled () {
105
- for _ , ch := range experimentalCharsetInfo {
106
- charsets = append (charsets , ch )
107
- }
108
- }
109
-
110
77
return charsets
111
78
}
112
79
@@ -154,11 +121,7 @@ func GetCharsetInfo(cs string) (*Charset, error) {
154
121
if c , ok := charsetInfos [strings .ToLower (cs )]; ok {
155
122
return c , nil
156
123
}
157
- if CharsetFeatEnabled () {
158
- if c , ok := experimentalCharsetInfo [strings .ToLower (cs )]; ok {
159
- return c , nil
160
- }
161
- }
124
+
162
125
return nil , errors .Errorf ("Unknown charset %s" , cs )
163
126
}
164
127
@@ -218,6 +181,8 @@ const (
218
181
// CollationLatin1 is the default collation for CharsetLatin1.
219
182
CollationLatin1 = "latin1_bin"
220
183
184
+ CollationGBKBin = "gbk_bin"
185
+
221
186
CharsetARMSCII8 = "armscii8"
222
187
CharsetBig5 = "big5"
223
188
CharsetBinary = "binary"
@@ -484,16 +449,16 @@ var collations = []*Collation{
484
449
// AddCharset adds a new charset.
485
450
// Use only when adding a custom charset to the parser.
486
451
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
495
453
}
496
454
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
+
497
462
// AddCollation adds a new collation.
498
463
// Use only when adding a custom collation to the parser.
499
464
func AddCollation (c * Collation ) {
@@ -504,17 +469,13 @@ func AddCollation(c *Collation) {
504
469
supportedCollations = append (supportedCollations , c )
505
470
}
506
471
507
- if charset , ok := charsets [c .CharsetName ]; ok {
472
+ if charset , ok := charsetInfos [c .CharsetName ]; ok {
508
473
charset .Collations [c .Name ] = c
509
474
}
510
475
}
511
476
512
477
// init method always puts to the end of file.
513
478
func init () {
514
- for _ , c := range charsetInfos {
515
- AddCharset (c )
516
- }
517
-
518
479
for _ , c := range collations {
519
480
AddCollation (c )
520
481
}
0 commit comments