Skip to content

Commit

Permalink
[parser] *: change default charset from utf8 to utf8mb4 (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
winkyao authored and ti-chi-bot committed Oct 9, 2021
1 parent 2095376 commit 6f2c711
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 16 deletions.
5 changes: 5 additions & 0 deletions parser/charset/charset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
16 changes: 9 additions & 7 deletions parser/mysql/charset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions parser/parser.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions parser/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -4072,8 +4072,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
}
Expand Down Expand Up @@ -4142,8 +4142,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
}

Expand Down
2 changes: 1 addition & 1 deletion parser/types/field_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 6f2c711

Please sign in to comment.