Skip to content

Commit

Permalink
executor: fix show create table null timestamp. (pingcap#1968)
Browse files Browse the repository at this point in the history
Without the extra 'NULL', the create table statement would fail to execute.
  • Loading branch information
coocood authored Nov 7, 2016
1 parent 6dd4571 commit b5cd34a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 3 additions & 0 deletions executor/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,9 @@ func (e *ShowExec) fetchShowCreateTable() error {
switch col.DefaultValue {
case nil:
if !mysql.HasNotNullFlag(col.Flag) {
if mysql.HasTimestampFlag(col.Flag) {
buf.WriteString(" NULL")
}
buf.WriteString(" DEFAULT NULL")
}
case "CURRENT_TIMESTAMP":
Expand Down
5 changes: 3 additions & 2 deletions executor/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,16 @@ func (s *testSuite) TestShow(c *C) {
a int primary key,
b double NOT NULL DEFAULT 2.0,
c varchar(10) NOT NULL,
d time unique
d time unique,
e timestamp NULL
);`
tk.MustExec(testSQL)
testSQL = "show create table ptest;"
result = tk.MustQuery(testSQL)
c.Check(result.Rows(), HasLen, 1)
row = result.Rows()[0]
expectedRow = []interface{}{
"ptest", "CREATE TABLE `ptest` (\n `a` int(11) NOT NULL,\n `b` double NOT NULL DEFAULT '2',\n `c` varchar(10) NOT NULL,\n `d` time DEFAULT NULL,\n PRIMARY KEY (`a`),\n UNIQUE KEY `d` (`d`)\n) ENGINE=InnoDB"}
"ptest", "CREATE TABLE `ptest` (\n `a` int(11) NOT NULL,\n `b` double NOT NULL DEFAULT '2',\n `c` varchar(10) NOT NULL,\n `d` time DEFAULT NULL,\n `e` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`a`),\n UNIQUE KEY `d` (`d`)\n) ENGINE=InnoDB"}
for i, r := range row {
c.Check(r, Equals, expectedRow[i])
}
Expand Down

0 comments on commit b5cd34a

Please sign in to comment.