|
40 | 40 | _ StmtNode = &PrepareStmt{} |
41 | 41 | _ StmtNode = &RollbackStmt{} |
42 | 42 | _ StmtNode = &SetPwdStmt{} |
| 43 | + _ StmtNode = &SetRoleStmt{} |
43 | 44 | _ StmtNode = &SetStmt{} |
44 | 45 | _ StmtNode = &UseStmt{} |
45 | 46 | _ StmtNode = &FlushStmt{} |
@@ -758,6 +759,60 @@ func (n *ChangeStmt) Accept(v Visitor) (Node, bool) { |
758 | 759 | return v.Leave(n) |
759 | 760 | } |
760 | 761 |
|
| 762 | +// SetRoleStmtType is the type for FLUSH statement. |
| 763 | +type SetRoleStmtType int |
| 764 | + |
| 765 | +// SetRole statement types. |
| 766 | +const ( |
| 767 | + SetRoleDefault SetRoleStmtType = iota |
| 768 | + SetRoleNone |
| 769 | + SetRoleAll |
| 770 | + SetRoleAllExcept |
| 771 | + SetRoleRegular |
| 772 | +) |
| 773 | + |
| 774 | +type SetRoleStmt struct { |
| 775 | + stmtNode |
| 776 | + |
| 777 | + SetRoleOpt SetRoleStmtType |
| 778 | + RoleList []*auth.RoleIdentity |
| 779 | +} |
| 780 | + |
| 781 | +func (n *SetRoleStmt) Restore(ctx *RestoreCtx) error { |
| 782 | + ctx.WriteKeyWord("SET ROLE") |
| 783 | + switch n.SetRoleOpt { |
| 784 | + case SetRoleDefault: |
| 785 | + ctx.WriteKeyWord(" DEFAULT") |
| 786 | + case SetRoleNone: |
| 787 | + ctx.WriteKeyWord(" NONE") |
| 788 | + case SetRoleAll: |
| 789 | + ctx.WriteKeyWord(" ALL") |
| 790 | + case SetRoleAllExcept: |
| 791 | + ctx.WriteKeyWord(" ALL EXCEPT") |
| 792 | + } |
| 793 | + for i, role := range n.RoleList { |
| 794 | + ctx.WritePlain(" ") |
| 795 | + err := role.Restore(ctx) |
| 796 | + if err != nil { |
| 797 | + return errors.Annotate(err, "An error occurred while restore SetRoleStmt.RoleList") |
| 798 | + } |
| 799 | + if i != len(n.RoleList)-1 { |
| 800 | + ctx.WritePlain(",") |
| 801 | + } |
| 802 | + } |
| 803 | + return nil |
| 804 | +} |
| 805 | + |
| 806 | +// Accept implements Node Accept interface. |
| 807 | +func (n *SetRoleStmt) Accept(v Visitor) (Node, bool) { |
| 808 | + newNode, skipChildren := v.Enter(n) |
| 809 | + if skipChildren { |
| 810 | + return v.Leave(newNode) |
| 811 | + } |
| 812 | + n = newNode.(*SetRoleStmt) |
| 813 | + return v.Leave(n) |
| 814 | +} |
| 815 | + |
761 | 816 | // UserSpec is used for parsing create user statement. |
762 | 817 | type UserSpec struct { |
763 | 818 | User *auth.UserIdentity |
|
0 commit comments