@@ -32,6 +32,11 @@ type TimezoneConversion struct {
32
32
ToTimezone string
33
33
}
34
34
35
+ type CharacterSetConversion struct {
36
+ ToCharset string
37
+ FromCharset string
38
+ }
39
+
35
40
type Column struct {
36
41
Name string
37
42
IsUnsigned bool
@@ -43,17 +48,22 @@ type Column struct {
43
48
// add Octet length for binary type, fix bytes with suffix "00" get clipped in mysql binlog.
44
49
// https://github.com/github/gh-ost/issues/909
45
50
BinaryOctetLength uint
51
+ charsetConversion * CharacterSetConversion
46
52
}
47
53
48
54
func (this * Column ) convertArg (arg interface {}, isUniqueKeyColumn bool ) interface {} {
49
55
if s , ok := arg .(string ); ok {
50
- // string, charset conversion
51
- if encoding , ok := charsetEncodingMap [this .Charset ]; ok {
52
- arg , _ = encoding .NewDecoder ().String (s )
56
+ arg2Bytes := []byte (s )
57
+ // convert to bytes if character string without charsetConversion.
58
+ if this .Charset != "" && this .charsetConversion == nil {
59
+ arg = arg2Bytes
60
+ } else {
61
+ if encoding , ok := charsetEncodingMap [this .Charset ]; ok {
62
+ arg , _ = encoding .NewDecoder ().String (s )
63
+ }
53
64
}
54
65
55
66
if this .Type == BinaryColumnType && isUniqueKeyColumn {
56
- arg2Bytes := []byte (arg .(string ))
57
67
size := len (arg2Bytes )
58
68
if uint (size ) < this .BinaryOctetLength {
59
69
buf := bytes .NewBuffer (arg2Bytes )
@@ -238,6 +248,10 @@ func (this *ColumnList) Len() int {
238
248
return len (this .columns )
239
249
}
240
250
251
+ func (this * ColumnList ) SetCharsetConversion (columnName string , fromCharset string , toCharset string ) {
252
+ this .GetColumn (columnName ).charsetConversion = & CharacterSetConversion {FromCharset : fromCharset , ToCharset : toCharset }
253
+ }
254
+
241
255
// UniqueKey is the combination of a key's name and columns
242
256
type UniqueKey struct {
243
257
Name string
0 commit comments