Skip to content

Commit

Permalink
add backport pingcap#12327 test
Browse files Browse the repository at this point in the history
  • Loading branch information
AilinKid committed Nov 6, 2019
1 parent ee3f518 commit af36d12
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
12 changes: 10 additions & 2 deletions executor/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -664,8 +664,16 @@ func (e *ShowExec) fetchShowCreateTable() error {
for i, col := range tb.Cols() {
fmt.Fprintf(&buf, " %s %s", escape(col.Name, sqlMode), col.GetTypeDesc())
if col.Charset != "binary" {
if col.Charset != tblCharset || col.Collate != tblCollate {
fmt.Fprintf(&buf, " CHARACTER SET %s COLLATE %s", col.Charset, col.Collate)
if col.Charset != tblCharset {
fmt.Fprintf(&buf, " CHARACTER SET %s", col.Charset)
}
if col.Collate != tblCollate {
fmt.Fprintf(&buf, " COLLATE %s", col.Collate)
} else {
defcol, err := charset.GetDefaultCollation(col.Charset)
if err == nil && defcol != col.Collate {
fmt.Fprintf(&buf, " COLLATE %s", col.Collate)
}
}
}
if col.IsGenerated() {
Expand Down
15 changes: 15 additions & 0 deletions executor/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,21 @@ func (s *testSuite2) TestShowCreateTable(c *C) {
" PARTITION p11 VALUES LESS THAN (12),\n"+
" PARTITION p12 VALUES LESS THAN (MAXVALUE)\n"+
")"))
//for issue #11831
tk.MustExec("create table ttt4(a varchar(123) default null collate utf8mb4_unicode_ci)engine=innodb default charset=utf8mb4 collate=utf8mb4_unicode_ci;")
tk.MustQuery("show create table `ttt4`").Check(testutil.RowsWithSep("|",
""+
"ttt4 CREATE TABLE `ttt4` (\n"+
" `a` varchar(123) COLLATE utf8mb4_unicode_ci DEFAULT NULL\n"+
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci",
))
tk.MustExec("create table ttt5(a varchar(123) default null)engine=innodb default charset=utf8mb4 collate=utf8mb4_bin;")
tk.MustQuery("show create table `ttt5`").Check(testutil.RowsWithSep("|",
""+
"ttt5 CREATE TABLE `ttt5` (\n"+
" `a` varchar(123) DEFAULT NULL\n"+
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin",
))
}

func (s *testSuite2) TestShowEscape(c *C) {
Expand Down

0 comments on commit af36d12

Please sign in to comment.