Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: change default charset from utf8 to utf8mb4 (#13) #68

Merged
merged 1 commit into from
Dec 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions 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 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.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.y
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion 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