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

update: optimize collation check of utf8mb3 #643

Merged
merged 2 commits into from
May 2, 2024
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
6 changes: 5 additions & 1 deletion session/session_inception.go
Original file line number Diff line number Diff line change
Expand Up @@ -6903,11 +6903,12 @@
}

func (s *session) checkCharset(charset string) bool {
if s.dbVersion < 80000 && strings.EqualFold(charset, "utf8mb3") {
if s.dbVersion < 50700 && strings.EqualFold(charset, "utf8mb3") {

Check warning on line 6906 in session/session_inception.go

View check run for this annotation

Codecov / codecov/patch

session/session_inception.go#L6906

Added line #L6906 was not covered by tests
s.appendErrorNo(ErrUnknownCharset, charset)
}
if s.inc.SupportCharset != "" {
for _, item := range strings.Split(s.inc.SupportCharset, ",") {
item = strings.TrimSpace(item)

Check warning on line 6911 in session/session_inception.go

View check run for this annotation

Codecov / codecov/patch

session/session_inception.go#L6911

Added line #L6911 was not covered by tests
if strings.EqualFold(item, charset) {
return true
}
Expand All @@ -6921,6 +6922,8 @@
func (s *session) checkCollation(collation string) bool {
if s.inc.SupportCollation != "" {
for _, item := range strings.Split(s.inc.SupportCollation, ",") {
// Support collation of utf8mb3 aliases
item = strings.TrimSpace(strings.ReplaceAll(item, "utf8mb3", "utf8"))

Check warning on line 6926 in session/session_inception.go

View check run for this annotation

Codecov / codecov/patch

session/session_inception.go#L6926

Added line #L6926 was not covered by tests
if strings.EqualFold(item, collation) {
return true
}
Expand All @@ -6934,6 +6937,7 @@
func (s *session) checkEngine(engine string) bool {
if s.inc.SupportEngine != "" {
for _, item := range strings.Split(s.inc.SupportEngine, ",") {
item = strings.TrimSpace(item)

Check warning on line 6940 in session/session_inception.go

View check run for this annotation

Codecov / codecov/patch

session/session_inception.go#L6940

Added line #L6940 was not covered by tests
if strings.EqualFold(item, engine) {
return true
}
Expand Down
2 changes: 1 addition & 1 deletion session/session_inception_exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ func (s *testSessionIncExecSuite) TestAlterTableAddColumn(c *C) {
config.GetGlobalConfig().Inc.EnableColumnCharset = true
config.GetGlobalConfig().Inc.SupportCharset = "utf8,utf8mb3,utf8mb4"
sql = "drop table if exists t1;create table t1(id int primary key);alter table t1 add column c1 varchar(10) character set utf8mb3;"
if s.DBVersion > 80000 {
if s.DBVersion > 50700 {
s.testErrorCode(c, sql)
} else {
s.testErrorCode(c, sql,
Expand Down
2 changes: 1 addition & 1 deletion session/session_inception_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ func (s *testSessionIncSuite) TestCreateTable(c *C) {
s.testErrorCode(c, sql)

sql = "create table t1(a int) character set utf8mb3;"
if s.DBVersion > 80000 {
if s.DBVersion > 50700 {
s.testErrorCode(c, sql)
} else {
s.testErrorCode(c, sql,
Expand Down
Loading