Skip to content

Commit

Permalink
parser: implement Restore for Assignment (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
924060929 authored and leoppro committed Jan 3, 2019
1 parent 3f871e5 commit 907865f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
9 changes: 8 additions & 1 deletion ast/dml.go
Expand Up @@ -932,7 +932,14 @@ type Assignment struct {

// Restore implements Node interface.
func (n *Assignment) Restore(ctx *RestoreCtx) error {
return errors.New("Not implemented")
if err := n.Column.Restore(ctx); err != nil {
return errors.Annotate(err, "An error occurred while restore Assignment.Column")
}
ctx.WritePlain("=")
if err := n.Expr.Restore(ctx); err != nil {
return errors.Annotate(err, "An error occurred while restore Assignment.Expr")
}
return nil
}

// Accept implements Node Accept interface.
Expand Down
11 changes: 11 additions & 0 deletions ast/dml_test.go
Expand Up @@ -289,6 +289,17 @@ func (tc *testDMLSuite) TestOrderByClauseRestore(c *C) {
RunNodeRestoreTest(c, testCases, "SELECT 1 FROM t1 UNION SELECT 2 FROM t2 %s", extractNodeFromUnionStmtFunc)
}

func (tc *testDMLSuite) TestAssignmentRestore(c *C) {
testCases := []NodeRestoreTestCase{
{"a=1", "`a`=1"},
{"b=1+2", "`b`=1+2"},
}
extractNodeFunc := func(node Node) Node {
return node.(*UpdateStmt).List[0]
}
RunNodeRestoreTest(c, testCases, "UPDATE t1 SET %s", extractNodeFunc)
}

func (ts *testDMLSuite) TestHavingClauseRestore(c *C) {
testCases := []NodeRestoreTestCase{
{"HAVING a", "HAVING `a`"},
Expand Down

0 comments on commit 907865f

Please sign in to comment.