Skip to content

Commit

Permalink
ddl: make TiDB treat charset and collate case insensitive pingcap#8577 (
Browse files Browse the repository at this point in the history
  • Loading branch information
winkyao authored Feb 18, 2019
1 parent 1e962c9 commit f9df5fa
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
13 changes: 13 additions & 0 deletions ddl/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,19 @@ func (s *testIntegrationSuite) TestEndIncluded(c *C) {
tk.MustExec("admin check table t")
}

func (s *testIntegrationSuite) TestCaseInsensitiveCharsetAndCollate(c *C) {
tk := testkit.NewTestKit(c, s.store)

tk.MustExec("create database if not exists test_charset_collate")
defer tk.MustExec("drop database test_charset_collate")
tk.MustExec("use test_charset_collate")
tk.MustExec("create table t(id int) ENGINE=InnoDB DEFAULT CHARSET=UTF8 COLLATE=UTF8_BIN;")
tk.MustExec("create table t1(id int) ENGINE=InnoDB DEFAULT CHARSET=UTF8 COLLATE=uTF8_BIN;")
tk.MustExec("create table t2(id int) ENGINE=InnoDB DEFAULT CHARSET=Utf8 COLLATE=utf8_BIN;")
tk.MustExec("create table t3(id int) ENGINE=InnoDB DEFAULT CHARSET=Utf8mb4 COLLATE=utf8MB4_BIN;")
tk.MustExec("create table t4(id int) ENGINE=InnoDB DEFAULT CHARSET=Utf8mb4 COLLATE=utf8MB4_general_ci;")
}

func newStoreWithBootstrap() (kv.Storage, *domain.Domain, error) {
store, err := mockstore.NewMockTikvStore()
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions util/charset/charset.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func ValidCharsetAndCollation(cs string, co string) bool {
cs = "utf8"
}

cs = strings.ToLower(cs)
c, ok := charsets[cs]
if !ok {
return false
Expand All @@ -94,6 +95,7 @@ func ValidCharsetAndCollation(cs string, co string) bool {
if co == "" {
return true
}
co = strings.ToLower(co)
_, ok = c.Collations[co]
if !ok {
return false
Expand Down
6 changes: 6 additions & 0 deletions util/charset/charset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ func (s *testCharsetSuite) TestValidCharset(c *C) {
{"utf8", "utf8_invalid_ci", false},
{"utf16", "utf16_bin", false},
{"gb2312", "gb2312_chinese_ci", false},
{"UTF8", "UTF8_BIN", true},
{"UTF8", "utf8_bin", true},
{"UTF8MB4", "utf8mb4_bin", true},
{"UTF8MB4", "UTF8MB4_bin", true},
{"UTF8MB4", "UTF8MB4_general_ci", true},
{"Utf8", "uTf8_bIN", true},
}
for _, tt := range tests {
testValidCharset(c, tt.cs, tt.co, tt.succ)
Expand Down

0 comments on commit f9df5fa

Please sign in to comment.