(ctx *sql.Context, funcColl *functions.Collection, fn *RoutineWithParams, ifExists bool)
| 109 | } |
| 110 | |
| 111 | func dropFunction(ctx *sql.Context, funcColl *functions.Collection, fn *RoutineWithParams, ifExists bool) error { |
| 112 | // TODO: provide db |
| 113 | schema, err := core.GetSchemaName(ctx, nil, fn.SchemaName) |
| 114 | if err != nil { |
| 115 | return err |
| 116 | } |
| 117 | var funcId = id.NewFunction(schema, fn.RoutineName) |
| 118 | if len(fn.Args) == 0 { |
| 119 | funcs, err := funcColl.GetFunctionOverloads(ctx, funcId) |
| 120 | if err != nil { |
| 121 | return err |
| 122 | } |
| 123 | if len(funcs) == 1 { |
| 124 | funcId = funcs[0].ID |
| 125 | } else if len(funcs) > 1 { |
| 126 | funcExists := funcColl.HasFunction(ctx, funcId) |
| 127 | if !funcExists { |
| 128 | return errors.Errorf(`function name "%s" is not unique`, fn.RoutineName) |
| 129 | } |
| 130 | } |
| 131 | } else { |
| 132 | var argTypes = make([]id.Type, len(fn.Args)) |
| 133 | for i, arg := range fn.Args { |
| 134 | argTypes[i] = arg.Type.ID |
| 135 | } |
| 136 | funcId = id.NewFunction(schema, fn.RoutineName, argTypes...) |
| 137 | } |
| 138 | funcExists := funcColl.HasFunction(ctx, funcId) |
| 139 | if !funcExists && ifExists { |
| 140 | return nil |
| 141 | } |
| 142 | return funcColl.DropFunction(ctx, funcId) |
| 143 | } |
no test coverage detected