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)
| 117 | // beforeTableDeletionCheckFuncsProcs is called from BeforeTableDeletion and handles checking for function and procedure |
| 118 | // parameters that use a table's type. |
| 119 | func 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 | } |
no test coverage detected