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: fix show default num and sequence #16450

Merged
merged 12 commits into from
Apr 17, 2020
2 changes: 2 additions & 0 deletions executor/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,8 @@ func ConstructResultOfShowCreateTable(ctx sessionctx.Context, tableInfo *model.T
if col.Tp == mysql.TypeBit {
defaultValBinaryLiteral := types.BinaryLiteral(defaultValStr)
fmt.Fprintf(buf, " DEFAULT %s", defaultValBinaryLiteral.ToBitLiteralString(true))
} else if types.IsTypeNumeric(col.Tp) || col.DefaultIsExpr {
fmt.Fprintf(buf, " DEFAULT %s", format.OutputFormat(defaultValStr))
} else {
fmt.Fprintf(buf, " DEFAULT '%s'", format.OutputFormat(defaultValStr))
}
Expand Down
25 changes: 25 additions & 0 deletions executor/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,31 @@ func (s *testSuite5) TestShowCreateTable(c *C) {
" `a` varchar(10) DEFAULT NULL\n"+
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin", // non-binary collate is kept.
))
// Test for issue #17 in bug competition, default num and sequence should be shown without quote.
tk.MustExec(`drop table if exists default_num`)
tk.MustExec("create table default_num(a int default 11)")
tk.MustQuery("show create table default_num").Check(testutil.RowsWithSep("|",
""+
"default_num CREATE TABLE `default_num` (\n"+
" `a` int(11) DEFAULT 11\n"+
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin",
))
tk.MustExec(`drop table if exists default_varchar`)
tk.MustExec("create table default_varchar(a varchar(10) default \"haha\")")
tk.MustQuery("show create table default_varchar").Check(testutil.RowsWithSep("|",
""+
"default_varchar CREATE TABLE `default_varchar` (\n"+
" `a` varchar(10) DEFAULT 'haha'\n"+
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin",
))
tk.MustExec(`drop table if exists default_sequence`)
tk.MustExec("create table default_sequence(a int default nextval(seq))")
tk.MustQuery("show create table default_sequence").Check(testutil.RowsWithSep("|",
""+
"default_sequence CREATE TABLE `default_sequence` (\n"+
" `a` int(11) DEFAULT nextval(`test`.`seq`)\n"+
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin",
))
}

func (s *testAutoRandomSuite) TestShowCreateTableAutoRandom(c *C) {
Expand Down