Skip to content

Commit

Permalink
parser: implement Restore for DeleteTableList
Browse files Browse the repository at this point in the history
  • Loading branch information
wangbo committed Dec 23, 2018
1 parent 651ad71 commit 0dbc11c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
10 changes: 9 additions & 1 deletion ast/dml.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions ast/dml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 0dbc11c

Please sign in to comment.