* plsample_func_handler * * Function called by the call handler for function execution. */
| 80 | * Function called by the call handler for function execution. |
| 81 | */ |
| 82 | static Datum |
| 83 | plsample_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. |
no test coverage detected