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

Method RowIter

server/node/drop_type.go:72–164  ·  view source on GitHub ↗

RowIter implements the interface sql.ExecSourceRel.

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

Source from the content-addressed store, hash-verified

70
71// RowIter implements the interface sql.ExecSourceRel.
72func (c *DropType) RowIter(ctx *sql.Context, r sql.Row) (sql.RowIter, error) {
73 var userRole auth.Role
74 auth.LockRead(func() {
75 userRole = auth.GetRole(ctx.Client().User)
76 })
77 if !userRole.IsValid() {
78 return nil, errors.Errorf(`role "%s" does not exist`, ctx.Client().User)
79 }
80
81 currentDb := ctx.GetCurrentDatabase()
82 if len(c.database) > 0 && c.database != currentDb {
83 return nil, errors.Errorf("DROP TYPE is currently only supported for the current database")
84 }
85 schema, err := core.GetSchemaName(ctx, nil, c.schName)
86 if err != nil {
87 return nil, err
88 }
89 collection, err := core.GetTypesCollectionFromContext(ctx, "")
90 if err != nil {
91 return nil, err
92 }
93 typeID := id.NewType(schema, c.typName)
94 typ, err := collection.GetType(ctx, typeID)
95 if err != nil {
96 return nil, err
97 }
98 if typ == nil {
99 if c.ifExists {
100 // TODO: issue a notice
101 return sql.RowsToRowIter(), nil
102 } else {
103 return nil, types.ErrTypeDoesNotExist.New(c.typName)
104 }
105 }
106 if c.cascade {
107 // TODO: handle cascade
108 return nil, errors.Errorf(`cascading type drops are not yet supported`)
109 }
110
111 if _, ok := types.IDToBuiltInDoltgresType[typ.ID]; ok {
112 return nil, types.ErrCannotDropSystemType.New(typ.String())
113 }
114
115 // TODO: use .IsArrayType() when we support OIDs, so Elem OID isn't 0
116 if typ.TypCategory == types.TypeCategory_ArrayTypes {
117 // TODO: get the base type name
118 // add HINT: You can drop type ___ instead. (base type)
119 arrTypeName := typ.String()
120 return nil, types.ErrCannotDropArrayType.New(arrTypeName, strings.TrimSuffix(arrTypeName, "[]"))
121 }
122
123 // iterate on all table columns to check if this type is currently used.
124 db, err := core.GetSqlDatabaseFromContext(ctx, "")
125 if err != nil {
126 return nil, err
127 }
128 tableNames, err := db.GetTableNames(ctx)
129 if err != nil {

Callers

nothing calls this directly

Calls 15

IsValidMethod · 0.95
LockReadFunction · 0.92
GetRoleFunction · 0.92
GetSchemaNameFunction · 0.92
NewTypeFunction · 0.92
DropTypeMethod · 0.80
ErrorfMethod · 0.65
GetTypeMethod · 0.65
StringMethod · 0.65
SchemaMethod · 0.65

Tested by

no test coverage detected