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

Function beforeTableDeletionCheckFuncsProcs

server/hook/delete_table.go:119–157  ·  view source on GitHub ↗

beforeTableDeletionCheckFuncsProcs is called from BeforeTableDeletion and handles checking for function and procedure parameters that use a table's type.

(ctx *sql.Context, doltTable *sqle.DoltTable, allDeletedTables []doltdb.TableName)

Source from the content-addressed store, hash-verified

117// beforeTableDeletionCheckFuncsProcs is called from BeforeTableDeletion and handles checking for function and procedure
118// parameters that use a table's type.
119func beforeTableDeletionCheckFuncsProcs(ctx *sql.Context, doltTable *sqle.DoltTable, allDeletedTables []doltdb.TableName) error {
120 tableName := doltTable.TableName()
121 tableAsType := id.NewType(tableName.Schema, tableName.Name)
122 funcsColl, err := core.GetFunctionsCollectionFromContext(ctx, "")
123 if err != nil {
124 return err
125 }
126 err = funcsColl.IterateFunctions(ctx, func(f functions.Function) (stop bool, err error) {
127 for _, paramType := range f.ParameterTypes {
128 if paramType == tableAsType {
129 // TODO: portion after newline should be in DETAILS but we don't yet support that in our error messages
130 return true, errors.Newf("cannot drop table %s because other objects depend on it\nfunction %s depends on type %s",
131 tableName.Name, f.Name().Name, tableName.Name)
132 }
133 }
134 return false, nil
135 })
136 if err != nil {
137 return err
138 }
139 procsColl, err := core.GetProceduresCollectionFromContext(ctx, "")
140 if err != nil {
141 return err
142 }
143 err = procsColl.IterateProcedures(ctx, func(p procedures.Procedure) (stop bool, err error) {
144 for _, paramType := range p.ParameterTypes {
145 if paramType == tableAsType {
146 // TODO: portion after newline should be in DETAILS but we don't yet support that in our error messages
147 return true, errors.Newf("cannot drop table %s because other objects depend on it\nfunction %s depends on type %s",
148 tableName.Name, p.Name().Name, tableName.Name)
149 }
150 }
151 return false, nil
152 })
153 if err != nil {
154 return err
155 }
156 return nil
157}

Callers 1

BeforeTableDeletionFunction · 0.85

Calls 7

NewTypeFunction · 0.92
IterateFunctionsMethod · 0.80
IterateProceduresMethod · 0.80
NameMethod · 0.65
TableNameMethod · 0.45

Tested by

no test coverage detected