* LookupFuncNameInternal * Workhorse for LookupFuncName/LookupFuncWithArgs * * In an error situation, e.g. can't find the function, then we return * InvalidOid and set *lookupError to indicate what went wrong. * * Possible errors: * FUNCLOOKUP_NOSUCHFUNC: we can't find a function of this name. * FUNCLOOKUP_AMBIGUOUS: more than one function matches. */
| 2101 | * FUNCLOOKUP_AMBIGUOUS: more than one function matches. |
| 2102 | */ |
| 2103 | static Oid |
| 2104 | LookupFuncNameInternal(ObjectType objtype, List *funcname, |
| 2105 | int nargs, const Oid *argtypes, |
| 2106 | bool include_out_arguments, bool missing_ok, |
| 2107 | FuncLookupError *lookupError) |
| 2108 | { |
| 2109 | Oid result = InvalidOid; |
| 2110 | FuncCandidateList clist; |
| 2111 | |
| 2112 | /* NULL argtypes allowed for nullary functions only */ |
| 2113 | Assert(argtypes != NULL || nargs == 0); |
| 2114 | |
| 2115 | /* Always set *lookupError, to forestall uninitialized-variable warnings */ |
| 2116 | *lookupError = FUNCLOOKUP_NOSUCHFUNC; |
| 2117 | |
| 2118 | /* Get list of candidate objects */ |
| 2119 | clist = FuncnameGetCandidates(funcname, nargs, NIL, false, false, |
| 2120 | include_out_arguments, missing_ok); |
| 2121 | |
| 2122 | /* Scan list for a match to the arg types (if specified) and the objtype */ |
| 2123 | for (; clist != NULL; clist = clist->next) |
| 2124 | { |
| 2125 | /* Check arg type match, if specified */ |
| 2126 | if (nargs >= 0) |
| 2127 | { |
| 2128 | /* if nargs==0, argtypes can be null; don't pass that to memcmp */ |
| 2129 | if (nargs > 0 && |
| 2130 | memcmp(argtypes, clist->args, nargs * sizeof(Oid)) != 0) |
| 2131 | continue; |
| 2132 | } |
| 2133 | |
| 2134 | /* Check for duplicates reported by FuncnameGetCandidates */ |
| 2135 | if (!OidIsValid(clist->oid)) |
| 2136 | { |
| 2137 | *lookupError = FUNCLOOKUP_AMBIGUOUS; |
| 2138 | return InvalidOid; |
| 2139 | } |
| 2140 | |
| 2141 | /* Check objtype match, if specified */ |
| 2142 | switch (objtype) |
| 2143 | { |
| 2144 | case OBJECT_FUNCTION: |
| 2145 | case OBJECT_AGGREGATE: |
| 2146 | /* Ignore procedures */ |
| 2147 | if (get_func_prokind(clist->oid) == PROKIND_PROCEDURE) |
| 2148 | continue; |
| 2149 | break; |
| 2150 | case OBJECT_PROCEDURE: |
| 2151 | /* Ignore non-procedures */ |
| 2152 | if (get_func_prokind(clist->oid) != PROKIND_PROCEDURE) |
| 2153 | continue; |
| 2154 | break; |
| 2155 | case OBJECT_ROUTINE: |
| 2156 | /* no restriction */ |
| 2157 | break; |
| 2158 | default: |
| 2159 | Assert(false); |
| 2160 | } |
no test coverage detected