From 07b68450460d70d82cd2a2cb5be4ac2cde26cbe0 Mon Sep 17 00:00:00 2001 From: exialin Date: Tue, 12 Feb 2019 15:54:06 +0800 Subject: [PATCH 1/3] parser: minor fix of #198 --- ast/misc.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ast/misc.go b/ast/misc.go index c068cbbcd..ace37f106 100755 --- a/ast/misc.go +++ b/ast/misc.go @@ -1314,7 +1314,7 @@ func (n ObjectTypeType) Restore(ctx *RestoreCtx) error { case ObjectTypeNone: // do nothing case ObjectTypeTable: - ctx.WriteKeyWord("TABLE ") + ctx.WriteKeyWord("TABLE") default: return errors.New("Unsupported object type") } @@ -1388,6 +1388,7 @@ func (n *RevokeStmt) Restore(ctx *RestoreCtx) error { ctx.WriteKeyWord(" ON ") if err := n.ObjectType.Restore(ctx); err != nil { return errors.Annotate(err, "An error occurred while restore RevokeStmt.ObjectType") + ctx.WritePlain(" ") } if err := n.Level.Restore(ctx); err != nil { return errors.Annotate(err, "An error occurred while restore RevokeStmt.Level") @@ -1446,6 +1447,7 @@ func (n *GrantStmt) Restore(ctx *RestoreCtx) error { ctx.WriteKeyWord(" ON ") if err := n.ObjectType.Restore(ctx); err != nil { return errors.Annotate(err, "An error occurred while restore GrantStmt.ObjectType") + ctx.WritePlain(" ") } if err := n.Level.Restore(ctx); err != nil { return errors.Annotate(err, "An error occurred while restore GrantStmt.Level") From 90e7645544a4c2278371c58d72c1c853de971178 Mon Sep 17 00:00:00 2001 From: exialin Date: Tue, 12 Feb 2019 16:03:58 +0800 Subject: [PATCH 2/3] fix --- ast/misc.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/ast/misc.go b/ast/misc.go index ace37f106..0dbed05a2 100755 --- a/ast/misc.go +++ b/ast/misc.go @@ -1386,8 +1386,10 @@ func (n *RevokeStmt) Restore(ctx *RestoreCtx) error { } } ctx.WriteKeyWord(" ON ") - if err := n.ObjectType.Restore(ctx); err != nil { - return errors.Annotate(err, "An error occurred while restore RevokeStmt.ObjectType") + if n.ObjectType != ObjectTypeNone { + if err := n.ObjectType.Restore(ctx); err != nil { + return errors.Annotate(err, "An error occurred while restore RevokeStmt.ObjectType") + } ctx.WritePlain(" ") } if err := n.Level.Restore(ctx); err != nil { @@ -1445,8 +1447,10 @@ func (n *GrantStmt) Restore(ctx *RestoreCtx) error { } } ctx.WriteKeyWord(" ON ") - if err := n.ObjectType.Restore(ctx); err != nil { - return errors.Annotate(err, "An error occurred while restore GrantStmt.ObjectType") + if n.ObjectType != ObjectTypeNone { + if err := n.ObjectType.Restore(ctx); err != nil { + return errors.Annotate(err, "An error occurred while restore GrantStmt.ObjectType") + } ctx.WritePlain(" ") } if err := n.Level.Restore(ctx); err != nil { From 32dccb66a66891ed5e890fa838cae930e2ec9942 Mon Sep 17 00:00:00 2001 From: exialin Date: Tue, 12 Feb 2019 16:12:10 +0800 Subject: [PATCH 3/3] add test case --- parser_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/parser_test.go b/parser_test.go index 1395b9bbe..6452a6269 100755 --- a/parser_test.go +++ b/parser_test.go @@ -2103,6 +2103,7 @@ func (s *testParserSuite) TestPrivilege(c *C) { // for grant statement {"GRANT ALL ON db1.* TO 'jeffrey'@'localhost';", true, "GRANT ALL ON `db1`.* TO `jeffrey`@`localhost`"}, + {"GRANT ALL ON TABLE db1.* TO 'jeffrey'@'localhost';", true, "GRANT ALL ON TABLE `db1`.* TO `jeffrey`@`localhost`"}, {"GRANT ALL ON db1.* TO 'jeffrey'@'localhost' WITH GRANT OPTION;", true, "GRANT ALL ON `db1`.* TO `jeffrey`@`localhost` WITH GRANT OPTION"}, {"GRANT SELECT ON db2.invoice TO 'jeffrey'@'localhost';", true, "GRANT SELECT ON `db2`.`invoice` TO `jeffrey`@`localhost`"}, {"GRANT ALL ON *.* TO 'someuser'@'somehost';", true, "GRANT ALL ON *.* TO `someuser`@`somehost`"},