Skip to content
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
81 changes: 78 additions & 3 deletions enginetest/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -1639,23 +1639,98 @@ var QueryTests = []QueryTest{
},
{
`SHOW COLLATION`,
[]sql.Row{{"utf8mb4_0900_ai_ci", "utf8mb4", int64(1), "Yes", "Yes", int64(1), "PAD SPACE"}},
[]sql.Row{
{
sql.Collation_binary.String(),
"binary",
sql.CollationToMySQLVals[sql.Collation_binary].ID,
sql.CollationToMySQLVals[sql.Collation_binary].IsDefault,
sql.CollationToMySQLVals[sql.Collation_binary].IsCompiled,
sql.CollationToMySQLVals[sql.Collation_binary].SortLen,
sql.CollationToMySQLVals[sql.Collation_binary].PadSpace,
},
{
sql.Collation_utf8_general_ci.String(),
"utf8",
sql.CollationToMySQLVals[sql.Collation_utf8_general_ci].ID,
sql.CollationToMySQLVals[sql.Collation_utf8_general_ci].IsDefault,
sql.CollationToMySQLVals[sql.Collation_utf8_general_ci].IsCompiled,
sql.CollationToMySQLVals[sql.Collation_utf8_general_ci].SortLen,
sql.CollationToMySQLVals[sql.Collation_utf8_general_ci].PadSpace,
},
{
sql.Collation_utf8mb4_0900_ai_ci.String(),
"utf8mb4",
sql.CollationToMySQLVals[sql.Collation_utf8mb4_0900_ai_ci].ID,
sql.CollationToMySQLVals[sql.Collation_utf8mb4_0900_ai_ci].IsDefault,
sql.CollationToMySQLVals[sql.Collation_utf8mb4_0900_ai_ci].IsCompiled,
sql.CollationToMySQLVals[sql.Collation_utf8mb4_0900_ai_ci].SortLen,
sql.CollationToMySQLVals[sql.Collation_utf8mb4_0900_ai_ci].PadSpace,
},
},
},
{
`SHOW COLLATION LIKE 'foo'`,
nil,
},
{
`SHOW COLLATION LIKE 'utf8%'`,
[]sql.Row{{"utf8mb4_0900_ai_ci", "utf8mb4", int64(1), "Yes", "Yes", int64(1), "PAD SPACE"}},
[]sql.Row{
{
sql.Collation_utf8_general_ci.String(),
"utf8",
sql.CollationToMySQLVals[sql.Collation_utf8_general_ci].ID,
sql.CollationToMySQLVals[sql.Collation_utf8_general_ci].IsDefault,
sql.CollationToMySQLVals[sql.Collation_utf8_general_ci].IsCompiled,
sql.CollationToMySQLVals[sql.Collation_utf8_general_ci].SortLen,
sql.CollationToMySQLVals[sql.Collation_utf8_general_ci].PadSpace,
},
{
sql.Collation_utf8mb4_0900_ai_ci.String(),
"utf8mb4",
sql.CollationToMySQLVals[sql.Collation_utf8mb4_0900_ai_ci].ID,
sql.CollationToMySQLVals[sql.Collation_utf8mb4_0900_ai_ci].IsDefault,
sql.CollationToMySQLVals[sql.Collation_utf8mb4_0900_ai_ci].IsCompiled,
sql.CollationToMySQLVals[sql.Collation_utf8mb4_0900_ai_ci].SortLen,
sql.CollationToMySQLVals[sql.Collation_utf8mb4_0900_ai_ci].PadSpace,
},
},
},
{
`SHOW COLLATION WHERE charset = 'foo'`,
nil,
},
{
"SHOW COLLATION WHERE `Default` = 'Yes'",
[]sql.Row{{"utf8mb4_0900_ai_ci", "utf8mb4", int64(1), "Yes", "Yes", int64(1), "PAD SPACE"}},
[]sql.Row{
{
sql.Collation_binary.String(),
"binary",
sql.CollationToMySQLVals[sql.Collation_binary].ID,
sql.CollationToMySQLVals[sql.Collation_binary].IsDefault,
sql.CollationToMySQLVals[sql.Collation_binary].IsCompiled,
sql.CollationToMySQLVals[sql.Collation_binary].SortLen,
sql.CollationToMySQLVals[sql.Collation_binary].PadSpace,
},
{
sql.Collation_utf8_general_ci.String(),
"utf8",
sql.CollationToMySQLVals[sql.Collation_utf8_general_ci].ID,
sql.CollationToMySQLVals[sql.Collation_utf8_general_ci].IsDefault,
sql.CollationToMySQLVals[sql.Collation_utf8_general_ci].IsCompiled,
sql.CollationToMySQLVals[sql.Collation_utf8_general_ci].SortLen,
sql.CollationToMySQLVals[sql.Collation_utf8_general_ci].PadSpace,
},
{
sql.Collation_utf8mb4_0900_ai_ci.String(),
"utf8mb4",
sql.CollationToMySQLVals[sql.Collation_utf8mb4_0900_ai_ci].ID,
sql.CollationToMySQLVals[sql.Collation_utf8mb4_0900_ai_ci].IsDefault,
sql.CollationToMySQLVals[sql.Collation_utf8mb4_0900_ai_ci].IsCompiled,
sql.CollationToMySQLVals[sql.Collation_utf8mb4_0900_ai_ci].SortLen,
sql.CollationToMySQLVals[sql.Collation_utf8mb4_0900_ai_ci].PadSpace,
},
},
},
{
"ROLLBACK",
Expand Down
73 changes: 71 additions & 2 deletions sql/charsetcollation.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const (
CharacterSet_utf16 CharacterSet = "utf16"
CharacterSet_utf16le CharacterSet = "utf16le"
CharacterSet_utf32 CharacterSet = "utf32"
CharacterSet_utf8 = CharacterSet_utf8mb3
CharacterSet_utf8 CharacterSet = "utf8"
CharacterSet_utf8mb3 CharacterSet = "utf8mb3"
CharacterSet_utf8mb4 CharacterSet = "utf8mb4"

Expand Down Expand Up @@ -230,7 +230,7 @@ const (
Collation_utf32_croatian_ci Collation = "utf32_croatian_ci"
Collation_utf32_unicode_520_ci Collation = "utf32_unicode_520_ci"
Collation_utf32_vietnamese_ci Collation = "utf32_vietnamese_ci"
Collation_utf8_general_ci = Collation_utf8mb3_general_ci
Collation_utf8_general_ci Collation = "utf8"
Collation_utf8_tolower_ci = Collation_utf8mb3_tolower_ci
Collation_utf8_bin = Collation_utf8mb3_bin
Collation_utf8_unicode_ci = Collation_utf8mb3_unicode_ci
Expand Down Expand Up @@ -1073,6 +1073,8 @@ var (
Collation_utf8mb4_ru_0900_as_cs: CharacterSet_utf8mb4,
Collation_utf8mb4_zh_0900_as_cs: CharacterSet_utf8mb4,
Collation_utf8mb4_0900_bin: CharacterSet_utf8mb4,
Collation_utf8_general_ci: CharacterSet_utf8,

}

characterSetDescriptions = map[CharacterSet]string{
Expand Down Expand Up @@ -1167,6 +1169,27 @@ var (
ErrCollationNotSupported = errors.NewKind("Unknown collation: %v")
)

const (
Y = "Yes"
N = "No"
NoPad = "NO PAD"
PadSpace = "PAD SPACE"
)

type mysqlCollationRow struct {
ID int64
IsDefault string
IsCompiled string
SortLen int64
PadSpace string
}

var CollationToMySQLVals = map[Collation]mysqlCollationRow{
Collation_binary: {63, Y, Y, 0, NoPad},
Collation_utf8_general_ci: {33, Y, Y, 1,PadSpace},
Collation_utf8mb4_0900_ai_ci: {255, Y, Y, 0, NoPad},
}

// ParseCharacterSet takes in a string representing a CharacterSet and
// returns the result if a match is found, or an error if not.
func ParseCharacterSet(str string) (CharacterSet, error) {
Expand Down Expand Up @@ -1273,3 +1296,49 @@ func (c Collation) WorksWithCharacterSet(cs CharacterSet) bool {
func (c Collation) String() string {
return string(c)
}

// ID returns the id of the Collation.
func (c Collation) ID() int64 {
s, ok := CollationToMySQLVals[c]
if !ok {
s := CollationToMySQLVals[Collation_Default]
return s.ID
}
return s.ID
}

// IsDefault returns string specifying id collation is default.
func (c Collation) IsDefault() string {
s, ok := CollationToMySQLVals[c]
if !ok {
return Y
}
return s.IsDefault
Comment on lines +1312 to +1316
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be

if c == Collation_Default {
  return Y
}
return N

instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leaving as is

}

// IsCompiled returns string specifying id collation is compiled.
func (c Collation) IsCompiled() string {
s, ok := CollationToMySQLVals[c]
if !ok {
return Y
}
return s.IsCompiled
}

// SortLen returns sort len of the collation.
func (c Collation) SortLen() int64 {
s, ok := CollationToMySQLVals[c]
if !ok {
return 1
}
return s.SortLen
}

// PadSpace returns pad space of the collation.
func (c Collation) PadSpace() string {
s, ok := CollationToMySQLVals[c]
if !ok {
return PadSpace
}
return s.PadSpace
}
22 changes: 13 additions & 9 deletions sql/information_schema/information_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,15 +502,19 @@ func schemataRowIter(ctx *Context, c *Catalog) RowIter {
}

func collationsRowIter(ctx *Context, c *Catalog) RowIter {
return RowsToRowIter(Row{
Collation_Default.String(),
Collation_Default.CharacterSet().String(),
int64(1),
"Yes",
"Yes",
int64(1),
"PAD SPACE",
})
var rows []Row
for c := range CollationToMySQLVals {
rows = append(rows, Row{
c.String(),
c.CharacterSet().String(),
c.ID(),
c.IsDefault(),
c.IsCompiled(),
c.SortLen(),
c.PadSpace(),
})
}
return RowsToRowIter(rows...)
}

func emptyRowIter(ctx *Context, c *Catalog) RowIter {
Expand Down