Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parser: implement Restore for Assignment #146

Merged
merged 1 commit into from Jan 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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