RowIter implements the interface sql.ExecSourceRel.
(ctx *sql.Context, r sql.Row)
| 64 | |
| 65 | // RowIter implements the interface sql.ExecSourceRel. |
| 66 | func (c *DropSequence) RowIter(ctx *sql.Context, r sql.Row) (sql.RowIter, error) { |
| 67 | schema, err := core.GetSchemaName(ctx, nil, c.schema) |
| 68 | if err != nil { |
| 69 | return nil, err |
| 70 | } |
| 71 | relationType, err := core.GetRelationType(ctx, schema, c.sequence) |
| 72 | if err != nil { |
| 73 | return nil, err |
| 74 | } |
| 75 | if relationType == core.RelationType_DoesNotExist { |
| 76 | if c.ifExists { |
| 77 | // TODO: issue a notice |
| 78 | return sql.RowsToRowIter(), nil |
| 79 | } |
| 80 | return nil, errors.Errorf(`sequence "%s" does not exist`, c.sequence) |
| 81 | } |
| 82 | // TODO: we always use the current database for this operation, but it should also be possible drop a sequence in |
| 83 | // a different DB (e.g. on a different branch) |
| 84 | collection, err := core.GetSequencesCollectionFromContext(ctx, ctx.GetCurrentDatabase()) |
| 85 | if err != nil { |
| 86 | return nil, err |
| 87 | } |
| 88 | sequenceID := id.NewSequence(schema, c.sequence) |
| 89 | sequence, err := collection.GetSequence(ctx, sequenceID) |
| 90 | if err != nil { |
| 91 | return nil, err |
| 92 | } |
| 93 | if sequence.OwnerTable.IsValid() { |
| 94 | if c.cascade { |
| 95 | // TODO: if the sequence is referenced by the column's default value, then we also need to delete the default |
| 96 | return nil, errors.Errorf(`cascading sequence drops are not yet supported`) |
| 97 | } else { |
| 98 | // TODO: this error is only true if the sequence is referenced by the column's default value |
| 99 | return nil, errors.Errorf(`cannot drop sequence %s because other objects depend on it`, c.sequence) |
| 100 | } |
| 101 | } |
| 102 | if err = collection.DropSequence(ctx, sequenceID); err != nil { |
| 103 | return nil, err |
| 104 | } |
| 105 | return sql.RowsToRowIter(), nil |
| 106 | } |
| 107 | |
| 108 | // Schema implements the interface sql.ExecSourceRel. |
| 109 | func (c *DropSequence) Schema(ctx *sql.Context) sql.Schema { |
nothing calls this directly
no test coverage detected