loadFunction loads the function with the given ID from the given collection. If the collection is nil, then this also loads the collection from the context.
(ctx *sql.Context, funcCollection *functions.Collection, funcID id.Function)
| 167 | // loadFunction loads the function with the given ID from the given collection. If the collection is nil, then this also |
| 168 | // loads the collection from the context. |
| 169 | func loadFunction(ctx *sql.Context, funcCollection *functions.Collection, funcID id.Function) (functions.Function, error) { |
| 170 | var err error |
| 171 | if funcCollection == nil { |
| 172 | funcCollection, err = core.GetFunctionsCollectionFromContext(ctx, "") |
| 173 | if err != nil { |
| 174 | return functions.Function{}, err |
| 175 | } |
| 176 | } |
| 177 | var function functions.Function |
| 178 | if len(funcID.SchemaName()) > 0 { |
| 179 | function, err = funcCollection.GetFunction(ctx, funcID) |
| 180 | if err != nil { |
| 181 | return functions.Function{}, err |
| 182 | } |
| 183 | } else { |
| 184 | searchPaths, err := core.SearchPath(ctx) |
| 185 | if err != nil { |
| 186 | return functions.Function{}, err |
| 187 | } |
| 188 | for _, searchPath := range searchPaths { |
| 189 | function, err = funcCollection.GetFunction(ctx, id.NewFunction(searchPath, funcID.FunctionName())) |
| 190 | if err != nil { |
| 191 | return functions.Function{}, err |
| 192 | } |
| 193 | if function.ID.IsValid() { |
| 194 | break |
| 195 | } |
| 196 | } |
| 197 | } |
| 198 | return function, nil |
| 199 | } |
no test coverage detected