diff --git a/charset/charset.go b/charset/charset.go index 0511f5540..c42c13e4b 100644 --- a/charset/charset.go +++ b/charset/charset.go @@ -115,6 +115,11 @@ func GetDefaultCollation(charset string) (string, error) { return c.DefaultCollation, nil } +// GetDefaultCharsetAndCollate returns the default charset and collation. +func GetDefaultCharsetAndCollate() (string, string) { + return mysql.DefaultCharset, mysql.DefaultCollationName +} + // GetCharsetInfo returns charset and collation for cs as name. func GetCharsetInfo(cs string) (string, string, error) { c, ok := charsets[strings.ToLower(cs)] diff --git a/mysql/charset.go b/mysql/charset.go index 9cd96796e..f2e99a437 100644 --- a/mysql/charset.go +++ b/mysql/charset.go @@ -551,13 +551,15 @@ var CollationNames = map[string]uint8{ // MySQL collation information. const ( - UTF8Charset = "utf8" - UTF8MB4Charset = "utf8mb4" - DefaultCharset = UTF8Charset - DefaultCollationID = 83 - BinaryCollationID = 63 - UTF8DefaultCollation = "utf8_bin" - DefaultCollationName = UTF8DefaultCollation + UTF8Charset = "utf8" + UTF8MB4Charset = "utf8mb4" + DefaultCharset = UTF8MB4Charset + // DefaultCollationID is utf8mb4_bin(46) + DefaultCollationID = 46 + BinaryCollationID = 63 + UTF8DefaultCollation = "utf8_bin" + UTF8MB4DefaultCollation = "utf8mb4_bin" + DefaultCollationName = UTF8MB4DefaultCollation // MaxBytesOfCharacter, is the max bytes length of a character, // refer to RFC3629, in UTF-8, characters from the U+0000..U+10FFFF range diff --git a/parser.go b/parser.go index 660154e37..402079603 100644 --- a/parser.go +++ b/parser.go @@ -9579,8 +9579,8 @@ yynewstate: x.Flag |= mysql.BinaryFlag } if x.Charset == "" { - x.Charset = charset.CharsetUTF8 - x.Collate = charset.CollationUTF8 + x.Charset = mysql.DefaultCharset + x.Collate = mysql.DefaultCollationName } parser.yyVAL.item = x } @@ -9649,8 +9649,8 @@ yynewstate: { x := types.NewFieldType(mysql.TypeJSON) x.Flag |= mysql.BinaryFlag | (mysql.ParseToJSONFlag) - x.Charset = charset.CharsetUTF8 - x.Collate = charset.CollationUTF8 + x.Charset = mysql.DefaultCharset + x.Collate = mysql.DefaultCollationName parser.yyVAL.item = x } case 824: diff --git a/parser.y b/parser.y index ace6555ea..614d3bd30 100644 --- a/parser.y +++ b/parser.y @@ -4201,8 +4201,8 @@ CastType: x.Flag |= mysql.BinaryFlag } if x.Charset == "" { - x.Charset = charset.CharsetUTF8 - x.Collate = charset.CollationUTF8 + x.Charset = mysql.DefaultCharset + x.Collate = mysql.DefaultCollationName } $$ = x } @@ -4271,8 +4271,8 @@ CastType: { x := types.NewFieldType(mysql.TypeJSON) x.Flag |= mysql.BinaryFlag | (mysql.ParseToJSONFlag) - x.Charset = charset.CharsetUTF8 - x.Collate = charset.CollationUTF8 + x.Charset = mysql.DefaultCharset + x.Collate = mysql.DefaultCollationName $$ = x } diff --git a/types/field_type.go b/types/field_type.go index 4b299cdb6..af2a2b291 100644 --- a/types/field_type.go +++ b/types/field_type.go @@ -204,7 +204,7 @@ func (ft *FieldType) FormatAsCastType(w io.Writer) { if ft.Flag&mysql.BinaryFlag != 0 { fmt.Fprint(w, " BINARY") } - if ft.Charset != charset.CharsetBin && ft.Charset != charset.CharsetUTF8 { + if ft.Charset != charset.CharsetBin && ft.Charset != mysql.DefaultCharset { fmt.Fprintf(w, " %s", ft.Charset) } case mysql.TypeDate: