|
33 | 33 | _ DDLNode = &DropDatabaseStmt{} |
34 | 34 | _ DDLNode = &DropIndexStmt{} |
35 | 35 | _ DDLNode = &DropTableStmt{} |
| 36 | + _ DDLNode = &DropSequenceStmt{} |
36 | 37 | _ DDLNode = &RenameTableStmt{} |
37 | 38 | _ DDLNode = &TruncateTableStmt{} |
38 | 39 | _ DDLNode = &RepairTableStmt{} |
@@ -1089,6 +1090,54 @@ func (n *DropTableStmt) Accept(v Visitor) (Node, bool) { |
1089 | 1090 | return v.Leave(n) |
1090 | 1091 | } |
1091 | 1092 |
|
| 1093 | +// DropSequenceStmt is a statement to drop a Sequence. |
| 1094 | +type DropSequenceStmt struct { |
| 1095 | + ddlNode |
| 1096 | + |
| 1097 | + IfExists bool |
| 1098 | + Sequences []*TableName |
| 1099 | + IsTemporary bool |
| 1100 | +} |
| 1101 | + |
| 1102 | +// Restore implements Node interface. |
| 1103 | +func (n *DropSequenceStmt) Restore(ctx *RestoreCtx) error { |
| 1104 | + if n.IsTemporary { |
| 1105 | + ctx.WriteKeyWord("DROP TEMPORARY SEQUENCE ") |
| 1106 | + } else { |
| 1107 | + ctx.WriteKeyWord("DROP SEQUENCE ") |
| 1108 | + } |
| 1109 | + if n.IfExists { |
| 1110 | + ctx.WriteKeyWord("IF EXISTS ") |
| 1111 | + } |
| 1112 | + for i, sequence := range n.Sequences { |
| 1113 | + if i != 0 { |
| 1114 | + ctx.WritePlain(", ") |
| 1115 | + } |
| 1116 | + if err := sequence.Restore(ctx); err != nil { |
| 1117 | + return errors.Annotatef(err, "An error occurred while restore DropSequenceStmt.Sequences[%d]", i) |
| 1118 | + } |
| 1119 | + } |
| 1120 | + |
| 1121 | + return nil |
| 1122 | +} |
| 1123 | + |
| 1124 | +// Accept implements Node Accept interface. |
| 1125 | +func (n *DropSequenceStmt) Accept(v Visitor) (Node, bool) { |
| 1126 | + newNode, skipChildren := v.Enter(n) |
| 1127 | + if skipChildren { |
| 1128 | + return v.Leave(newNode) |
| 1129 | + } |
| 1130 | + n = newNode.(*DropSequenceStmt) |
| 1131 | + for i, val := range n.Sequences { |
| 1132 | + node, ok := val.Accept(v) |
| 1133 | + if !ok { |
| 1134 | + return n, false |
| 1135 | + } |
| 1136 | + n.Sequences[i] = node.(*TableName) |
| 1137 | + } |
| 1138 | + return v.Leave(n) |
| 1139 | +} |
| 1140 | + |
1092 | 1141 | // RenameTableStmt is a statement to rename a table. |
1093 | 1142 | // See http://dev.mysql.com/doc/refman/5.7/en/rename-table.html |
1094 | 1143 | type RenameTableStmt struct { |
|
0 commit comments