From 0dbc11c555e0e4cc95a2060c5e57719cf9f58e17 Mon Sep 17 00:00:00 2001 From: wangbo <506340561@qq.com> Date: Sun, 23 Dec 2018 20:46:55 +0800 Subject: [PATCH] parser: implement Restore for DeleteTableList --- ast/dml.go | 10 +++++++++- ast/dml_test.go | 10 ++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/ast/dml.go b/ast/dml.go index d29c88415..37ddff487 100644 --- a/ast/dml.go +++ b/ast/dml.go @@ -234,7 +234,15 @@ type DeleteTableList struct { // Restore implements Node interface. func (n *DeleteTableList) Restore(ctx *RestoreCtx) error { - return errors.New("Not implemented") + for i, t := range n.Tables { + if err := t.Restore(ctx); err != nil { + return errors.Annotate(err, "An error occurred while restore DeleteTableList.Tablename") + } + if i != len(n.Tables) - 1 { + ctx.WritePlain(",") + } + } + return nil } // Accept implements Node Accept interface. diff --git a/ast/dml_test.go b/ast/dml_test.go index 266765977..f1a87d17a 100644 --- a/ast/dml_test.go +++ b/ast/dml_test.go @@ -139,3 +139,13 @@ func (tc *testDMLSuite) TestLimitRestore(c *C) { RunNodeRestoreTest(c, testCases, "SELECT 1 %s", extractNodeFunc) } +func (tc *testDMLSuite) TestDeleteTableListRestore(c *C) { + testCases := []NodeRestoreTestCase{ + {"t1,t2", "`t1`,`t2`"}, + } + extractNodeFunc := func(node Node) Node { + return node.(*DeleteStmt).Tables + } + RunNodeRestoreTest(c, testCases, "DELETE %s FROM t1 INNER JOIN t2 INNER JOIN t3 WHERE t1.id=t2.id AND t2.id=t3.id;", extractNodeFunc) + RunNodeRestoreTest(c, testCases, "DELETE FROM %s USING t1 INNER JOIN t2 INNER JOIN t3 WHERE t1.id=t2.id AND t2.id=t3.id;", extractNodeFunc) +}