diff --git a/parser/ast/ddl.go b/parser/ast/ddl.go index f1bae2514e..326e74f104 100644 --- a/parser/ast/ddl.go +++ b/parser/ast/ddl.go @@ -578,7 +578,25 @@ type DropTableStmt struct { // Restore implements Node interface. func (n *DropTableStmt) Restore(ctx *RestoreCtx) error { - return errors.New("Not implemented") + if n.IsView { + ctx.WriteKeyWord("DROP VIEW ") + } else { + ctx.WriteKeyWord("DROP TABLE ") + } + if n.IfExists { + ctx.WriteKeyWord("IF EXISTS ") + } + + for index, table := range n.Tables { + if index != 0 { + ctx.WritePlain(", ") + } + if err := table.Restore(ctx); err != nil { + return errors.Annotate(err, "An error occurred while restore DropTableStmt.Tables "+string(index)) + } + } + + return nil } // Accept implements Node Accept interface. diff --git a/parser/parser_test.go b/parser/parser_test.go index 3517f7c44d..420d0678a0 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -1543,21 +1543,22 @@ func (s *testParserSuite) TestDDL(c *C) { {"drop schema xxx", true, ""}, {"drop schema if exists xxx", true, ""}, {"drop schema if not exists xxx", false, ""}, - {"drop table", false, ""}, - {"drop table xxx", true, ""}, - {"drop table xxx, yyy", true, ""}, + {"drop table", false, "DROP TABLE"}, + {"drop table xxx", true, "DROP TABLE `xxx`"}, + {"drop table xxx, yyy", true, "DROP TABLE `xxx`, `yyy`"}, {"drop tables xxx", true, ""}, {"drop tables xxx, yyy", true, ""}, - {"drop table if exists xxx", true, ""}, + {"drop table if exists xxx", true, "DROP TABLE IF EXISTS `xxx`"}, + {"drop table if exists xxx, yyy", true, "DROP TABLE IF EXISTS `xxx`, `yyy`"}, {"drop table if not exists xxx", false, ""}, {"drop table xxx restrict", true, ""}, {"drop table xxx, yyy cascade", true, ""}, {"drop table if exists xxx restrict", true, ""}, - {"drop view", false, ""}, - {"drop view xxx", true, ""}, - {"drop view xxx, yyy", true, ""}, - {"drop view if exists xxx", true, ""}, - {"drop view if exists xxx, yyy", true, ""}, + {"drop view", false, "DROP VIEW"}, + {"drop view xxx", true, "DROP VIEW `xxx`"}, + {"drop view xxx, yyy", true, "DROP VIEW `xxx`, `yyy`"}, + {"drop view if exists xxx", true, "DROP VIEW IF EXISTS `xxx`"}, + {"drop view if exists xxx, yyy", true, "DROP VIEW IF EXISTS `xxx`, `yyy`"}, {"drop stats t", true, "DROP STATS `t`"}, // for issue 974 {`CREATE TABLE address (