MCPcopy Create free account
hub / github.com/apache/cloudberry / ValidateProtocolFunction

Function ValidateProtocolFunction

src/backend/catalog/pg_extprotocol.c:192–266  ·  view source on GitHub ↗

* ValidateProtocolFunction -- common code for finding readfn, writefn or validatorfn */

Source from the content-addressed store, hash-verified

190 * ValidateProtocolFunction -- common code for finding readfn, writefn or validatorfn
191 */
192static Oid
193ValidateProtocolFunction(List *fnName, ExtPtcFuncType fntype)
194{
195 Oid fnOid;
196 bool retset;
197 Oid *true_oid_array;
198 Oid actual_rettype;
199 Oid desired_rettype;
200 FuncDetailCode fdresult;
201 AclResult aclresult;
202 Oid inputTypes[1] = {InvalidOid}; /* dummy */
203 int nargs = 0; /* true for all 3 function types at the moment */
204 int nvargs;
205 Oid vatype;
206
207 if (fntype == EXTPTC_FUNC_VALIDATOR)
208 desired_rettype = VOIDOID;
209 else
210 desired_rettype = INT4OID;
211
212 /*
213 * func_get_detail looks up the function in the catalogs, does
214 * disambiguation for polymorphic functions, handles inheritance, and
215 * returns the funcid and type and set or singleton status of the
216 * function's return value. it also returns the true argument types to
217 * the function.
218 */
219 fdresult = func_get_detail(fnName, NIL, NIL,
220 nargs, inputTypes, false, false, false,
221 &fnOid, &actual_rettype, &retset,
222 &nvargs, &vatype, &true_oid_array, NULL);
223
224 /* only valid case is a normal function not returning a set */
225 if (fdresult != FUNCDETAIL_NORMAL || !OidIsValid(fnOid))
226 ereport(ERROR,
227 (errcode(ERRCODE_UNDEFINED_FUNCTION),
228 errmsg("function %s does not exist",
229 func_signature_string(fnName, nargs, NIL, inputTypes))));
230
231 if (OidIsValid(vatype))
232 ereport(ERROR,
233 (errcode(ERRCODE_DATATYPE_MISMATCH),
234 errmsg("Invalid protocol function"),
235 errdetail("Protocol functions cannot be variadic.")));
236
237 if (retset)
238 ereport(ERROR,
239 (errcode(ERRCODE_DATATYPE_MISMATCH),
240 errmsg("Invalid protocol function"),
241 errdetail("Protocol functions cannot return sets.")));
242
243 if (actual_rettype != desired_rettype)
244 ereport(ERROR,
245 (errcode(ERRCODE_DATATYPE_MISMATCH),
246 errmsg("%s protocol function %s must return %s",
247 func_type_to_name(fntype),
248 func_signature_string(fnName, nargs, NIL, inputTypes),
249 (fntype == EXTPTC_FUNC_VALIDATOR ? "void" : "an integer"))));

Callers 1

ExtProtocolCreateFunction · 0.85

Calls 12

func_get_detailFunction · 0.85
func_signature_stringFunction · 0.85
func_type_to_nameFunction · 0.85
func_volatileFunction · 0.85
pg_proc_aclcheckFunction · 0.85
GetUserIdFunction · 0.85
aclcheck_errorFunction · 0.85
get_func_nameFunction · 0.85
errcodeFunction · 0.50
errmsgFunction · 0.50
errdetailFunction · 0.50
errhintFunction · 0.50

Tested by

no test coverage detected