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

Function plsample_func_handler

src/test/modules/plsample/plsample.c:82–187  ·  view source on GitHub ↗

* plsample_func_handler * * Function called by the call handler for function execution. */

Source from the content-addressed store, hash-verified

80 * Function called by the call handler for function execution.
81 */
82static Datum
83plsample_func_handler(PG_FUNCTION_ARGS)
84{
85 HeapTuple pl_tuple;
86 Datum ret;
87 char *source;
88 bool isnull;
89 FmgrInfo *arg_out_func;
90 Form_pg_type type_struct;
91 HeapTuple type_tuple;
92 Form_pg_proc pl_struct;
93 volatile MemoryContext proc_cxt = NULL;
94 Oid *argtypes;
95 char **argnames;
96 char *argmodes;
97 char *proname;
98 Form_pg_type pg_type_entry;
99 Oid result_typioparam;
100 Oid prorettype;
101 FmgrInfo result_in_func;
102 int numargs;
103
104 /* Fetch the source text of the function. */
105 pl_tuple = SearchSysCache(PROCOID,
106 ObjectIdGetDatum(fcinfo->flinfo->fn_oid), 0, 0, 0);
107 if (!HeapTupleIsValid(pl_tuple))
108 elog(ERROR, "cache lookup failed for function %u",
109 fcinfo->flinfo->fn_oid);
110
111 /*
112 * Extract and print the source text of the function. This can be used as
113 * a base for the function validation and execution.
114 */
115 pl_struct = (Form_pg_proc) GETSTRUCT(pl_tuple);
116 proname = pstrdup(NameStr(pl_struct->proname));
117 ret = SysCacheGetAttr(PROCOID, pl_tuple, Anum_pg_proc_prosrc, &isnull);
118 if (isnull)
119 elog(ERROR, "could not find source text of function \"%s\"",
120 proname);
121 source = DatumGetCString(DirectFunctionCall1(textout, ret));
122 ereport(NOTICE,
123 (errmsg("source text of function \"%s\": %s",
124 proname, source)));
125
126 /*
127 * Allocate a context that will hold all the Postgres data for the
128 * procedure.
129 */
130 proc_cxt = AllocSetContextCreate(TopMemoryContext,
131 "PL/Sample function",
132 ALLOCSET_SMALL_SIZES);
133
134 arg_out_func = (FmgrInfo *) palloc0(fcinfo->nargs * sizeof(FmgrInfo));
135 numargs = get_func_arg_info(pl_tuple, &argtypes, &argnames, &argmodes);
136
137 /*
138 * Iterate through all of the function arguments, printing each input
139 * value.

Callers 1

plsample_call_handlerFunction · 0.85

Calls 14

SearchSysCacheFunction · 0.85
ObjectIdGetDatumFunction · 0.85
SysCacheGetAttrFunction · 0.85
DatumGetCStringFunction · 0.85
get_func_arg_infoFunction · 0.85
SearchSysCache1Function · 0.85
fmgr_info_cxtFunction · 0.85
ReleaseSysCacheFunction · 0.85
OutputFunctionCallFunction · 0.85
getTypeIOParamFunction · 0.85
InputFunctionCallFunction · 0.85
pstrdupFunction · 0.50

Tested by

no test coverage detected