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

executor: add column character sets when show create table #8866

Merged
merged 20 commits into from
Jan 14, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 3 additions & 0 deletions executor/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,9 @@ func (e *ShowExec) fetchShowCreateTable() error {
var hasAutoIncID bool
for i, col := range tb.Cols() {
fmt.Fprintf(&buf, " %s %s", escape(col.Name, sqlMode), col.GetTypeDesc())
if col.Collate != tb.Meta().Collate && col.Charset != tb.Meta().Charset {
fmt.Fprintf(&buf, " CHARSET %s COLLATE %s", col.Charset, col.Collate)
}
if col.IsGenerated() {
// It's a generated column.
fmt.Fprintf(&buf, " GENERATED ALWAYS AS (%s)", col.GeneratedExprString)
Expand Down
6 changes: 3 additions & 3 deletions executor/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,11 @@ func (s *testSuite2) TestShowEscape(c *C) {

tk.MustExec("use test")
tk.MustExec("drop table if exists `t``abl\"e`")
tk.MustExec("create table `t``abl\"e`(`c``olum\"n` int(11) primary key)")
tk.MustExec("create table `t``abl\"e`(`c``olum\"n` int(11) charset 'utf8' primary key)")
tk.MustQuery("show create table `t``abl\"e`").Check(testutil.RowsWithSep("|",
""+
"t`abl\"e CREATE TABLE `t``abl\"e` (\n"+
" `c``olum\"n` int(11) NOT NULL,\n"+
" `c``olum\"n` int(11) CHARSET utf8 COLLATE utf8_bin NOT NULL,\n"+
" PRIMARY KEY (`c``olum\"n`)\n"+
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin",
))
Expand All @@ -317,7 +317,7 @@ func (s *testSuite2) TestShowEscape(c *C) {
tk.MustQuery("show create table \"t`abl\"\"e\"").Check(testutil.RowsWithSep("|",
""+
"t`abl\"e CREATE TABLE \"t`abl\"\"e\" (\n"+
" \"c`olum\"\"n\" int(11) NOT NULL,\n"+
" \"c`olum\"\"n\" int(11) CHARSET utf8 COLLATE utf8_bin NOT NULL,\n"+
" PRIMARY KEY (\"c`olum\"\"n\")\n"+
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin",
))
Expand Down