MCPcopy Create free account
hub / github.com/dolthub/doltgresql / RowIter

Method RowIter

server/node/drop_sequence.go:66–106  ·  view source on GitHub ↗

RowIter implements the interface sql.ExecSourceRel.

(ctx *sql.Context, r sql.Row)

Source from the content-addressed store, hash-verified

64
65// RowIter implements the interface sql.ExecSourceRel.
66func (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.
109func (c *DropSequence) Schema(ctx *sql.Context) sql.Schema {

Callers

nothing calls this directly

Calls 8

GetSchemaNameFunction · 0.92
GetRelationTypeFunction · 0.92
NewSequenceFunction · 0.92
GetSequenceMethod · 0.80
DropSequenceMethod · 0.80
ErrorfMethod · 0.65
IsValidMethod · 0.45

Tested by

no test coverage detected