[parser] impl Restore of DropTableStmt (#107)

This commit is contained in:
He Cao
2018-12-24 10:34:47 +08:00
committed by Ti Chi Robot
parent 28b04d0276
commit 023cd7dcfb
2 changed files with 29 additions and 10 deletions

View File

@ -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.

View File

@ -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 (