32 #include "utils/fmgroids.h"
43 #define TEXTDOMAIN PG_TEXTDOMAIN("plperl")
47 #include "perlchunks.h"
50 #include "plperl_opmask.h"
127 #define increment_prodesc_refcount(prodesc) \
128 ((prodesc)->fn_refcount++)
129 #define decrement_prodesc_refcount(prodesc) \
131 Assert((prodesc)->fn_refcount > 0); \
132 if (--((prodesc)->fn_refcount) == 0) \
133 free_plperl_function(prodesc); \
237 static OP *(*pp_require_orig) (
pTHX) = NULL;
260 bool is_event_trigger);
276 int *ndims,
int *dims,
int cur_depth,
299 #if defined(WIN32) && PERL_VERSION_LT(5, 28, 0)
302 #define setlocale_perl(a,b) Perl_setlocale(a,b)
361 sv = HeSVKEY_force(he);
390 static bool inited =
false;
405 gettext_noop(
"If true, trusted and untrusted Perl code will be compiled in strict mode."),
419 gettext_noop(
"Perl initialization code to execute when a Perl interpreter is initialized."),
441 gettext_noop(
"Perl initialization code to execute once when plperl is first used."),
449 gettext_noop(
"Perl initialization code to execute once when plperlu is first used."),
558 PerlInterpreter *interp = NULL;
572 interp_desc->
interp = NULL;
642 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
643 errmsg(
"cannot allocate multiple Perl interpreters on this platform")));
659 newXS(
"PostgreSQL::InServer::SPI::bootstrap",
662 eval_pv(
"PostgreSQL::InServer::SPI::bootstrap()", FALSE);
665 (
errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
667 errcontext(
"while executing PostgreSQL::InServer::SPI::bootstrap")));
671 interp_desc->
interp = interp;
689 PERL_SET_CONTEXT(interp_desc->
interp);
704 static PerlInterpreter *
707 PerlInterpreter *plperl;
709 static char *embedding[3 + 2] = {
710 "",
"-e", PLC_PERLBOOT
744 save_collate = loc ?
pstrdup(loc) : NULL;
746 save_ctype = loc ?
pstrdup(loc) : NULL;
748 save_monetary = loc ?
pstrdup(loc) : NULL;
750 save_numeric = loc ?
pstrdup(loc) : NULL;
752 save_time = loc ?
pstrdup(loc) : NULL;
754 #define PLPERL_RESTORE_LOCALE(name, saved) \
756 if (saved != NULL) { setlocale_perl(name, saved); pfree(saved); } \
762 embedding[nargs++] =
"-e";
775 #if defined(PERL_SYS_INIT3) && !defined(MYMALLOC)
777 static int perl_sys_init_done;
780 if (!perl_sys_init_done)
782 char *dummy_env[1] = {NULL};
784 PERL_SYS_INIT3(&nargs, (
char ***) &embedding, (
char ***) &dummy_env);
797 perl_sys_init_done = 1;
804 plperl = perl_alloc();
806 elog(
ERROR,
"could not allocate Perl interpreter");
808 PERL_SET_CONTEXT(plperl);
809 perl_construct(plperl);
819 PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
834 #ifdef PLPERL_ENABLE_OPMASK_EARLY
847 nargs, embedding, NULL) != 0)
849 (
errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
851 errcontext(
"while parsing Perl initialization")));
853 if (perl_run(plperl) != 0)
855 (
errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
857 errcontext(
"while running Perl initialization")));
859 #ifdef PLPERL_RESTORE_LOCALE
860 PLPERL_RESTORE_LOCALE(LC_COLLATE, save_collate);
861 PLPERL_RESTORE_LOCALE(LC_CTYPE, save_ctype);
862 PLPERL_RESTORE_LOCALE(LC_MONETARY, save_monetary);
863 PLPERL_RESTORE_LOCALE(LC_NUMERIC, save_numeric);
864 PLPERL_RESTORE_LOCALE(LC_TIME, save_time);
894 svp = hv_fetch(GvHVn(PL_incgv),
name,
len, 0);
898 DIE(
aTHX_ "Unable to load %s into plperl",
name);
920 if (interp && *interp)
935 if (PL_exit_flags & PERL_EXIT_DESTRUCT_END)
942 if (PL_endav && !PL_minus_c)
943 call_list(PL_scopestack_ix, PL_endav);
969 eval_pv(PLC_TRUSTED, FALSE);
972 (
errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
981 eval_pv(
"my $a=chr(0x100); return $a =~ /\\xa9/i", FALSE);
984 (
errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
1003 stash = gv_stashpv(
"DynaLoader", GV_ADDWARN);
1005 while ((sv = hv_iternextsv(stash, &
key, &klen)))
1009 SvREFCNT_dec(GvCV(sv));
1015 ++PL_sub_generation;
1016 hv_clear(PL_stashcache);
1027 (
errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
1029 errcontext(
"while executing plperl.on_plperl_init")));
1050 (
errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
1052 errcontext(
"while executing plperl.on_plperlu_init")));
1066 while (
len > 0 && isspace((
unsigned char)
res[
len - 1]))
1085 memset(nulls,
true,
sizeof(
bool) * td->
natts);
1087 hv_iterinit(perlhash);
1088 while ((he = hv_iternext(perlhash)))
1090 SV *
val = HeVAL(he);
1097 (
errcode(ERRCODE_UNDEFINED_COLUMN),
1098 errmsg(
"Perl hash contains nonexistent column \"%s\"",
1102 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1103 errmsg(
"cannot set system attribute \"%s\"",
1116 hv_iterinit(perlhash);
1142 if (SvOK(sv) && SvROK(sv))
1144 if (SvTYPE(SvRV(sv)) == SVt_PVAV)
1146 else if (sv_isa(sv,
"PostgreSQL::InServer::ARRAY"))
1148 HV *hv = (HV *) SvRV(sv);
1151 if (*sav && SvOK(*sav) && SvROK(*sav) &&
1152 SvTYPE(SvRV(*sav)) == SVt_PVAV)
1155 elog(
ERROR,
"could not get array reference from PostgreSQL::InServer::ARRAY object");
1166 int *ndims,
int *dims,
int cur_depth,
1172 int len = av_len(
av) + 1;
1174 for (
i = 0;
i <
len;
i++)
1177 SV **svp = av_fetch(
av,
i, FALSE);
1185 AV *nav = (AV *) SvRV(sav);
1188 if (cur_depth + 1 >
MAXDIM)
1190 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
1191 errmsg(
"number of array dimensions (%d) exceeds the maximum allowed (%d)",
1192 cur_depth + 1,
MAXDIM)));
1195 if (
i == 0 && *ndims == cur_depth)
1197 dims[*ndims] = av_len(nav) + 1;
1200 else if (av_len(nav) + 1 != dims[cur_depth])
1202 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
1203 errmsg(
"multidimensional arrays must have array expressions with matching dimensions")));
1207 ndims, dims, cur_depth + 1,
1208 arraytypid, elemtypid, typmod,
1217 if (*ndims != cur_depth)
1219 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
1220 errmsg(
"multidimensional arrays must have array expressions with matching dimensions")));
1255 (
errcode(ERRCODE_DATATYPE_MISMATCH),
1256 errmsg(
"cannot convert Perl array to non-array type %s",
1263 memset(dims, 0,
sizeof(dims));
1264 dims[0] = av_len((AV *) SvRV(src)) + 1;
1268 typid, elemtypid, typmod,
1269 &finfo, typioparam);
1275 for (
i = 0;
i < ndims;
i++)
1290 &typinput, typioparam);
1325 if (!sv || !SvOK(sv) || typid == VOIDOID)
1349 else if (SvTYPE(SvRV(sv)) == SVt_PVHV)
1358 (
errcode(ERRCODE_DATATYPE_MISMATCH),
1359 errmsg(
"cannot convert Perl hash to non-composite type %s",
1366 isdomain = (typid != td->
tdtypeid);
1380 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1381 errmsg(
"function returning record called in context "
1382 "that cannot accept type record")));
1403 fcinfo, finfo, typioparam,
1441 (
errcode(ERRCODE_UNDEFINED_OBJECT),
1442 errmsg(
"lookup failed for type %s", fqtypename)));
1453 &typoutput, &typisvarlena);
1475 Oid transform_funcid;
1492 &typdelim, &typioparam, &typoutputfunc);
1512 if (info->
ndims == 0)
1524 info->
nelems[0] = nitems;
1532 (void) hv_store(hv,
"array", 5,
av, 0);
1533 (void) hv_store(hv,
"typeoid", 7,
newSVuv(typid), 0);
1536 gv_stashpv(
"PostgreSQL::InServer::ARRAY", 0));
1558 if (nest >= info->
ndims - 1)
1562 for (
i = first;
i < last;
i += info->
nelems[nest + 1])
1567 av_push(result, ref);
1581 AV *result = newAV();
1583 for (
i = first;
i < last;
i++)
1591 av_push(result, newSV(0));
1709 when =
"INSTEAD OF";
1717 level =
"STATEMENT";
1762 (
errcode(ERRCODE_UNDEFINED_COLUMN),
1763 errmsg(
"$_TD->{new} does not exist")));
1764 if (!SvOK(*svp) || !SvROK(*svp) || SvTYPE(SvRV(*svp)) != SVt_PVHV)
1766 (
errcode(ERRCODE_DATATYPE_MISMATCH),
1767 errmsg(
"$_TD->{new} is not a hash reference")));
1768 hvNew = (HV *) SvRV(*svp);
1771 natts = tupdesc->
natts;
1774 modnulls = (
bool *)
palloc0(natts *
sizeof(
bool));
1775 modrepls = (
bool *)
palloc0(natts *
sizeof(
bool));
1778 while ((he = hv_iternext(hvNew)))
1781 SV *
val = HeVAL(he);
1787 (
errcode(ERRCODE_UNDEFINED_COLUMN),
1788 errmsg(
"Perl hash contains nonexistent column \"%s\"",
1792 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1793 errmsg(
"cannot set system attribute \"%s\"",
1795 if (attr->attgenerated)
1797 (
errcode(ERRCODE_E_R_I_E_TRIGGER_PROTOCOL_VIOLATED),
1798 errmsg(
"cannot set generated column \"%s\"",
1807 &modnulls[attn - 1]);
1808 modrepls[attn - 1] =
true;
1844 MemSet(&this_call_data, 0,
sizeof(this_call_data));
1845 this_call_data.
fcinfo = fcinfo;
1890 MemSet(&this_call_data, 0,
sizeof(this_call_data));
1895 pl_error_context.
arg = NULL;
1904 MemSet(&flinfo, 0,
sizeof(flinfo));
1905 MemSet(&desc, 0,
sizeof(desc));
1906 fake_fcinfo->flinfo = &flinfo;
1910 desc.
proname =
"inline_code_block";
1924 this_call_data.
fcinfo = fake_fcinfo;
1925 this_call_data.
prodesc = &desc;
1935 elog(
ERROR,
"could not connect to SPI manager");
1942 elog(
ERROR,
"could not create internal procedure for anonymous code block");
1983 bool is_trigger =
false;
1984 bool is_event_trigger =
false;
1993 elog(
ERROR,
"cache lookup failed for function %u", funcoid);
2000 if (functyptype == TYPTYPE_PSEUDO)
2002 if (proc->prorettype == TRIGGEROID)
2004 else if (proc->prorettype == EVENT_TRIGGEROID)
2005 is_event_trigger =
true;
2006 else if (proc->prorettype != RECORDOID &&
2007 proc->prorettype != VOIDOID)
2009 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2010 errmsg(
"PL/Perl functions cannot return type %s",
2016 &argtypes, &argnames, &argmodes);
2017 for (
i = 0;
i < numargs;
i++)
2020 argtypes[
i] != RECORDOID)
2022 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2023 errmsg(
"PL/Perl functions cannot accept type %s",
2084 HV *pragma_hv = newHV();
2106 PUSHs(sv_2mortal(
cstr2sv(s)));
2114 count =
call_pv(
"PostgreSQL::InServer::mkfunc",
2115 G_SCALAR | G_EVAL | G_KEEPERR);
2120 SV *sub_rv = (SV *) POPs;
2122 if (sub_rv && SvROK(sub_rv) && SvTYPE(SvRV(sub_rv)) == SVt_PVCV)
2134 (
errcode(ERRCODE_SYNTAX_ERROR),
2139 (
errcode(ERRCODE_SYNTAX_ERROR),
2140 errmsg(
"didn't get a CODE reference from compiling function \"%s\"",
2154 char *file = __FILE__;
2157 newXS(
"PostgreSQL::InServer::Util::bootstrap",
2171 Oid *argtypes = NULL;
2178 EXTEND(sp, desc->
nargs);
2193 PUSHs(sv_2mortal(sv));
2214 PUSHs(sv_2mortal(sv));
2230 (
errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
2231 errmsg(
"didn't get a return item from function")));
2242 (
errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
2246 retval = newSVsv(POPs);
2271 TDsv =
get_sv(
"main::_TD", 0);
2274 (
errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
2275 errmsg(
"couldn't fetch $_TD")));
2281 EXTEND(sp, tg_trigger->
tgnargs);
2298 (
errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
2299 errmsg(
"didn't get a return item from trigger function")));
2310 (
errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
2314 retval = newSVsv(POPs);
2338 TDsv =
get_sv(
"main::_TD", 0);
2341 (
errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
2342 errmsg(
"couldn't fetch $_TD")));
2361 (
errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
2362 errmsg(
"didn't get a return item from trigger function")));
2373 (
errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
2377 retval = newSVsv(POPs);
2395 nonatomic = fcinfo->context &&
2400 elog(
ERROR,
"could not connect to SPI manager");
2419 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2420 errmsg(
"set-valued function called in context that cannot accept a set")));
2424 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2425 errmsg(
"materialize mode required, but it is not allowed in this context")));
2457 AV *rav = (AV *) SvRV(sav);
2459 while ((svp = av_fetch(rav,
i, FALSE)) != NULL)
2465 else if (SvOK(perlret))
2468 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2469 errmsg(
"set-returning PL/Perl function must return "
2470 "reference to array or use return_next")));
2518 elog(
ERROR,
"could not connect to SPI manager");
2540 hvTD = (HV *) SvRV(svTD);
2551 if (perlret == NULL || !SvOK(perlret))
2589 (
errcode(ERRCODE_E_R_I_E_TRIGGER_PROTOCOL_VIOLATED),
2590 errmsg(
"ignoring modified row in DELETE trigger")));
2597 (
errcode(ERRCODE_E_R_I_E_TRIGGER_PROTOCOL_VIOLATED),
2598 errmsg(
"result of PL/Perl trigger function must be undef, "
2599 "\"SKIP\", or \"MODIFY\"")));
2626 elog(
ERROR,
"could not connect to SPI manager");
2657 if (proc_ptr && proc_ptr->
proc_ptr)
2716 elog(
ERROR,
"cache lookup failed for function %u", fn_oid);
2759 plperl_error_context.
arg =
NameStr(procStruct->proname);
2768 Datum protrftypes_datum;
2789 prodesc->
fn_cxt = proc_cxt;
2793 prodesc->
nargs = procStruct->pronargs;
2801 (procStruct->provolatile != PROVOLATILE_VOLATILE);
2805 Anum_pg_proc_protrftypes, &isnull);
2816 elog(
ERROR,
"cache lookup failed for language %u",
2817 procStruct->prolang);
2819 prodesc->
lang_oid = langStruct->oid;
2827 if (!is_trigger && !is_event_trigger)
2829 Oid rettype = procStruct->prorettype;
2833 elog(
ERROR,
"cache lookup failed for type %u", rettype);
2837 if (typeStruct->typtype == TYPTYPE_PSEUDO)
2839 if (rettype == VOIDOID ||
2840 rettype == RECORDOID)
2842 else if (rettype == TRIGGEROID ||
2843 rettype == EVENT_TRIGGEROID)
2845 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2846 errmsg(
"trigger functions can only be called "
2850 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2851 errmsg(
"PL/Perl functions cannot return type %s",
2872 if (!is_trigger && !is_event_trigger)
2876 for (
i = 0;
i < prodesc->
nargs;
i++)
2878 Oid argtype = procStruct->proargtypes.values[
i];
2882 elog(
ERROR,
"cache lookup failed for type %u", argtype);
2886 if (typeStruct->typtype == TYPTYPE_PSEUDO &&
2887 argtype != RECORDOID)
2889 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2890 errmsg(
"PL/Perl functions cannot accept type %s",
2904 if (IsTrueArrayType(typeStruct))
2919 Anum_pg_proc_prosrc, &isnull);
2939 elog(
ERROR,
"could not create PL/Perl internal procedure");
3022 hv_ksplit(hv, tupdesc->
natts);
3024 for (
i = 0;
i < tupdesc->
natts;
i++)
3033 if (att->attisdropped)
3036 if (att->attgenerated)
3039 if (!include_generated)
3098 croak(
"SPI functions can not be used in END blocks");
3113 croak(
"SPI functions can not be used during function compilation");
3192 (processed > (uint64)
UV_MAX) ?
3193 newSVnv((
NV) processed) :
3196 if (
status > 0 && tuptable)
3205 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
3206 errmsg(
"query result has too many rows to fit in a Perl array")));
3209 av_extend(rows, processed);
3210 for (
i = 0;
i < processed;
i++)
3277 (
errcode(ERRCODE_SYNTAX_ERROR),
3278 errmsg(
"cannot use return_next in a non-SETOF function")));
3300 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3301 errmsg(
"function returning record called in context "
3302 "that cannot accept type record")));
3311 if (tupdesc == NULL || tupdesc->
natts != 1)
3312 elog(
ERROR,
"expected single-column result descriptor for non-composite SETOF result");
3339 "PL/Perl return_next temporary cxt",
3349 if (!(SvOK(sv) && SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVHV))
3351 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3352 errmsg(
"SETOF-composite-returning PL/Perl function "
3353 "must call return_next with reference to hash")));
3424 elog(
ERROR,
"SPI_cursor_open() failed:%s",
3581 "PL/Perl spi_prepare query",
3587 qdesc->
nargs = argc;
3598 "PL/Perl spi_prepare workspace",
3607 for (
i = 0;
i < argc;
i++)
3735 if (hash_entry == NULL)
3736 elog(
ERROR,
"spi_exec_prepared: Invalid prepared query passed");
3740 elog(
ERROR,
"spi_exec_prepared: plperl query_hash value vanished");
3742 if (qdesc->
nargs != argc)
3743 elog(
ERROR,
"spi_exec_prepared: expected %d argument(s), %d passed",
3744 qdesc->
nargs, argc);
3753 if (sv && *sv && SvIOK(*sv))
3761 nulls = (
char *)
palloc(argc);
3770 for (
i = 0;
i < argc;
i++)
3781 nulls[
i] = isnull ?
'n' :
' ';
3858 if (hash_entry == NULL)
3859 elog(
ERROR,
"spi_query_prepared: Invalid prepared query passed");
3863 elog(
ERROR,
"spi_query_prepared: plperl query_hash value vanished");
3865 if (qdesc->
nargs != argc)
3866 elog(
ERROR,
"spi_query_prepared: expected %d argument(s), %d passed",
3867 qdesc->
nargs, argc);
3874 nulls = (
char *)
palloc(argc);
3883 for (
i = 0;
i < argc;
i++)
3894 nulls[
i] = isnull ?
'n' :
' ';
3908 elog(
ERROR,
"SPI_cursor_open() failed:%s",
3956 if (hash_entry == NULL)
3957 elog(
ERROR,
"spi_freeplan: Invalid prepared query passed");
3961 elog(
ERROR,
"spi_freeplan: plperl query_hash value vanished");
4043 char *
volatile cmsg = NULL;
4053 elog(level,
"%s", cmsg);
4092 hlen = -(int) strlen(hkey);
4093 ret = hv_store(hv, hkey, hlen,
val, 0);
4116 hlen = -(int) strlen(hkey);
4117 ret = hv_fetch(hv, hkey, hlen, 0);
4131 char *procname = (
char *)
arg;
4134 errcontext(
"PL/Perl function \"%s\"", procname);
4143 char *procname = (
char *)
arg;
4146 errcontext(
"compilation of PL/Perl function \"%s\"", procname);
4165 #if defined(WIN32) && PERL_VERSION_LT(5, 28, 0)
4174 #ifdef USE_LOCALE_CTYPE
4175 if (category == LC_CTYPE
4177 || category == LC_ALL
4184 if (category == LC_ALL)
4189 new_ctype(newctype);
4192 #ifdef USE_LOCALE_COLLATE
4193 if (category == LC_COLLATE
4195 || category == LC_ALL
4202 if (category == LC_ALL)
4207 new_collate(newcoll);
4211 #ifdef USE_LOCALE_NUMERIC
4212 if (category == LC_NUMERIC
4214 || category == LC_ALL
4221 if (category == LC_ALL)
4226 new_numeric(newnum);
#define DatumGetArrayTypeP(X)
ArrayBuildState * accumArrayResult(ArrayBuildState *astate, Datum dvalue, bool disnull, Oid element_type, MemoryContext rcontext)
ArrayBuildState * initArrayResult(Oid element_type, MemoryContext rcontext, bool subcontext)
Datum makeMdArrayResult(ArrayBuildState *astate, int ndims, int *dims, int *lbs, MemoryContext rcontext, bool release)
void deconstruct_array(ArrayType *array, Oid elmtype, int elmlen, bool elmbyval, char elmalign, Datum **elemsp, bool **nullsp, int *nelemsp)
static Datum values[MAXATTR]
#define TextDatumGetCString(d)
#define MemSet(start, val, len)
#define PG_USED_FOR_ASSERTS_ONLY
#define OidIsValid(objectId)
const char * GetCommandTagName(CommandTag commandTag)
static void PGresult * res
elog(ERROR, "%s: %s", p2, msg)
void domain_check(Datum value, bool isnull, Oid domainType, void **extra, MemoryContext mcxt)
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
HTAB * hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)
void * hash_seq_search(HASH_SEQ_STATUS *status)
void hash_seq_init(HASH_SEQ_STATUS *status, HTAB *hashp)
ErrorContextCallback * error_context_stack
void FlushErrorState(void)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
ErrorData * CopyErrorData(void)
#define ereport(elevel,...)
#define CALLED_AS_EVENT_TRIGGER(fcinfo)
@ SFRM_Materialize_Random
bool CheckFunctionValidatorAccess(Oid validatorOid, Oid functionOid)
Datum InputFunctionCall(FmgrInfo *flinfo, char *str, Oid typioparam, int32 typmod)
void fmgr_info(Oid functionId, FmgrInfo *finfo)
void fmgr_info_cxt(Oid functionId, FmgrInfo *finfo, MemoryContext mcxt)
char * OidOutputFunctionCall(Oid functionId, Datum val)
char * OutputFunctionCall(FmgrInfo *flinfo, Datum val)
#define OidFunctionCall1(functionId, arg1)
#define DatumGetHeapTupleHeader(X)
#define PG_GETARG_POINTER(n)
#define SizeForFunctionCallInfo(nargs)
#define DirectFunctionCall1(func, arg1)
#define LOCAL_FCINFO(name, nargs)
#define FunctionCall1(flinfo, arg1)
int get_func_arg_info(HeapTuple procTup, Oid **p_argtypes, char ***p_argnames, char **p_argmodes)
TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc)
@ TYPEFUNC_COMPOSITE_DOMAIN
static Datum HeapTupleGetDatum(const HeapTupleData *tuple)
void DefineCustomStringVariable(const char *name, const char *short_desc, const char *long_desc, char **valueAddr, const char *bootValue, GucContext context, int flags, GucStringCheckHook check_hook, GucStringAssignHook assign_hook, GucShowHook show_hook)
void DefineCustomBoolVariable(const char *name, const char *short_desc, const char *long_desc, bool *valueAddr, bool bootValue, GucContext context, int flags, GucBoolCheckHook check_hook, GucBoolAssignHook assign_hook, GucShowHook show_hook)
void MarkGUCPrefixReserved(const char *className)
bool check_function_bodies
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
HeapTuple heap_modify_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *replValues, bool *replIsnull, bool *doReplace)
#define HeapTupleIsValid(tuple)
static Datum heap_getattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
#define HeapTupleHeaderGetTypMod(tup)
#define HeapTupleHeaderGetTypeId(tup)
#define HeapTupleHeaderGetDatumLength(tup)
#define HeapTupleHeaderGetRawXmin(tup)
void on_proc_exit(pg_on_exit_callback function, Datum arg)
if(TABLE==NULL||TABLE_index==NULL)
bool ItemPointerEquals(ItemPointer pointer1, ItemPointer pointer2)
Assert(fmt[strlen(fmt) - 1] !='\n')
Oid get_element_type(Oid typid)
bool type_is_rowtype(Oid typid)
void getTypeOutputInfo(Oid type, Oid *typOutput, bool *typIsVarlena)
Oid get_func_signature(Oid funcid, Oid **argtypes, int *nargs)
void getTypeInputInfo(Oid type, Oid *typInput, Oid *typIOParam)
Oid get_transform_tosql(Oid typid, Oid langid, List *trftypes)
void get_type_io_data(Oid typid, IOFuncSelector which_func, int16 *typlen, bool *typbyval, char *typalign, char *typdelim, Oid *typioparam, Oid *func)
char get_typtype(Oid typid)
Oid get_base_element_type(Oid typid)
Oid getTypeIOParam(HeapTuple typeTuple)
Oid get_transform_fromsql(Oid typid, Oid langid, List *trftypes)
bool pg_verifymbstr(const char *mbstr, int len, bool noError)
char * pg_server_to_any(const char *s, int len, int encoding)
void MemoryContextReset(MemoryContext context)
char * pstrdup(const char *in)
void pfree(void *pointer)
MemoryContext TopMemoryContext
void * palloc0(Size size)
MemoryContext CurrentMemoryContext
void MemoryContextDelete(MemoryContext context)
void MemoryContextSetIdentifier(MemoryContext context, const char *id)
#define AllocSetContextCreate
#define ALLOCSET_DEFAULT_SIZES
#define ALLOCSET_SMALL_SIZES
#define CHECK_FOR_INTERRUPTS()
void pg_bindtextdomain(const char *domain)
#define IsA(nodeptr, _type_)
#define castNode(_type_, nodeptr)
Datum oidout(PG_FUNCTION_ARGS)
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
bool parseTypeString(const char *str, Oid *typeid_p, int32 *typmod_p, Node *escontext)
FormData_pg_attribute * Form_pg_attribute
FormData_pg_language * Form_pg_language
List * oid_array_to_list(Datum datum)
FormData_pg_proc * Form_pg_proc
static void static void status(const char *fmt,...) pg_attribute_printf(1
FormData_pg_type * Form_pg_type
static HTAB * plperl_interp_hash
static SV * plperl_call_perl_func(plperl_proc_desc *desc, FunctionCallInfo fcinfo)
struct plperl_call_data plperl_call_data
static char plperl_opmask[MAXO]
static void plperl_event_trigger_handler(PG_FUNCTION_ARGS)
static bool plperl_use_strict
static void _sv_to_datum_finfo(Oid typid, FmgrInfo *finfo, Oid *typioparam)
static Datum plperl_func_handler(PG_FUNCTION_ARGS)
struct plperl_proc_key plperl_proc_key
SV * plperl_spi_query(char *query)
static HTAB * plperl_proc_hash
static void set_interp_require(bool trusted)
static bool plperl_ending
static void SvREFCNT_dec_current(SV *sv)
void plperl_return_next(SV *sv)
static SV * plperl_hash_from_tuple(HeapTuple tuple, TupleDesc tupdesc, bool include_generated)
struct plperl_query_desc plperl_query_desc
SV * plperl_spi_query_prepared(char *query, int argc, SV **argv)
static plperl_interp_desc * plperl_active_interp
Datum plperlu_call_handler(PG_FUNCTION_ARGS)
static PerlInterpreter * plperl_held_interp
static HV * plperl_spi_execute_fetch_result(SPITupleTable *, uint64, int)
static void plperl_trusted_init(void)
static SV * make_array_ref(plperl_array_info *info, int first, int last)
HV * plperl_spi_exec(char *query, int limit)
void plperl_spi_rollback(void)
Datum plperl_inline_handler(PG_FUNCTION_ARGS)
static HeapTuple plperl_build_tuple_result(HV *perlhash, TupleDesc td)
struct plperl_proc_desc plperl_proc_desc
static void plperl_untrusted_init(void)
SV * plperl_spi_fetchrow(char *cursor)
static void plperl_create_sub(plperl_proc_desc *desc, const char *s, Oid fn_oid)
Datum plperl_validator(PG_FUNCTION_ARGS)
static void plperl_init_shared_libs(pTHX)
#define increment_prodesc_refcount(prodesc)
static char * hek2cstr(HE *he)
static void plperl_destroy_interp(PerlInterpreter **)
EXTERN_C void boot_DynaLoader(pTHX_ CV *cv)
static char * strip_trailing_ws(const char *msg)
static OP * pp_require_safe(pTHX)
HV * plperl_spi_exec_prepared(char *query, HV *attr, int argc, SV **argv)
#define setlocale_perl(a, b)
struct plperl_array_info plperl_array_info
char * plperl_sv_to_literal(SV *sv, char *fqtypename)
static void free_plperl_function(plperl_proc_desc *prodesc)
EXTERN_C void boot_PostgreSQL__InServer__Util(pTHX_ CV *cv)
static SV * plperl_event_trigger_build_args(FunctionCallInfo fcinfo)
static void check_spi_usage_allowed(void)
static SV * plperl_trigger_build_args(FunctionCallInfo fcinfo)
PG_FUNCTION_INFO_V1(plperl_call_handler)
SV * plperl_spi_prepare(char *query, int argc, SV **argv)
static SV * plperl_hash_from_datum(Datum attr)
static void select_perl_context(bool trusted)
static Datum plperl_sv_to_datum(SV *sv, Oid typid, int32 typmod, FunctionCallInfo fcinfo, FmgrInfo *finfo, Oid typioparam, bool *isnull)
struct plperl_query_entry plperl_query_entry
static void plperl_fini(int code, Datum arg)
static void plperl_exec_callback(void *arg)
static void plperl_inline_callback(void *arg)
static SV * get_perl_array_ref(SV *sv)
static SV * plperl_call_perl_trigger_func(plperl_proc_desc *desc, FunctionCallInfo fcinfo, SV *td)
static SV ** hv_fetch_string(HV *hv, const char *key)
#define decrement_prodesc_refcount(prodesc)
Datum plperlu_inline_handler(PG_FUNCTION_ARGS)
static void plperl_compile_callback(void *arg)
Datum plperlu_validator(PG_FUNCTION_ARGS)
void plperl_spi_freeplan(char *query)
static SV * plperl_ref_from_pg_array(Datum arg, Oid typid)
static Datum plperl_array_to_datum(SV *src, Oid typid, int32 typmod)
static char * plperl_on_init
static char * plperl_on_plperl_init
static SV * split_array(plperl_array_info *info, int first, int last, int nest)
static Datum plperl_trigger_handler(PG_FUNCTION_ARGS)
Datum plperl_call_handler(PG_FUNCTION_ARGS)
static SV ** hv_store_string(HV *hv, const char *key, SV *val)
static plperl_call_data * current_call_data
void plperl_util_elog(int level, SV *msg)
void plperl_spi_cursor_close(char *cursor)
static plperl_proc_desc * compile_plperl_function(Oid fn_oid, bool is_trigger, bool is_event_trigger)
static OP *(* pp_require_orig)(pTHX)
static HeapTuple plperl_modify_tuple(HV *hvTD, TriggerData *tdata, HeapTuple otup)
static void plperl_return_next_internal(SV *sv)
struct plperl_proc_ptr plperl_proc_ptr
struct plperl_interp_desc plperl_interp_desc
static bool validate_plperl_function(plperl_proc_ptr *proc_ptr, HeapTuple procTup)
static void plperl_call_perl_event_trigger_func(plperl_proc_desc *desc, FunctionCallInfo fcinfo, SV *td)
static PerlInterpreter * plperl_init_interp(void)
EXTERN_C void boot_PostgreSQL__InServer__SPI(pTHX_ CV *cv)
static char * plperl_on_plperlu_init
static Datum plperl_hash_to_datum(SV *src, TupleDesc td)
static void array_to_datum_internal(AV *av, ArrayBuildState *astate, int *ndims, int *dims, int cur_depth, Oid arraytypid, Oid elemtypid, int32 typmod, FmgrInfo *finfo, Oid typioparam)
void plperl_spi_commit(void)
static void activate_interpreter(plperl_interp_desc *interp_desc)
static SV * cstr2sv(const char *str)
static void croak_cstr(const char *str)
static char * sv2cstr(SV *sv)
int pg_strcasecmp(const char *s1, const char *s2)
pqsigfunc pqsignal(int signo, pqsigfunc func)
void PinPortal(Portal portal)
void UnpinPortal(Portal portal)
void FloatExceptionHandler(SIGNAL_ARGS)
void check_stack_depth(void)
static Datum PointerGetDatum(const void *X)
static char * DatumGetCString(Datum X)
static Datum ObjectIdGetDatum(Oid X)
static Pointer DatumGetPointer(Datum X)
static Datum CStringGetDatum(const char *X)
#define PERL_UNUSED_VAR(x)
Datum regtypein(PG_FUNCTION_ARGS)
ResourceOwner CurrentResourceOwner
char * SPI_getrelname(Relation rel)
int SPI_fnumber(TupleDesc tupdesc, const char *fname)
int SPI_freeplan(SPIPlanPtr plan)
SPITupleTable * SPI_tuptable
Portal SPI_cursor_find(const char *name)
const char * SPI_result_code_string(int code)
void SPI_cursor_fetch(Portal portal, bool forward, long count)
int SPI_execute_plan(SPIPlanPtr plan, Datum *Values, const char *Nulls, bool read_only, long tcount)
int SPI_register_trigger_data(TriggerData *tdata)
void SPI_freetuptable(SPITupleTable *tuptable)
Portal SPI_cursor_open(const char *name, SPIPlanPtr plan, Datum *Values, const char *Nulls, bool read_only)
SPIPlanPtr SPI_prepare(const char *src, int nargs, Oid *argtypes)
int SPI_keepplan(SPIPlanPtr plan)
void SPI_cursor_close(Portal portal)
char * SPI_getnspname(Relation rel)
int SPI_connect_ext(int options)
int SPI_execute(const char *src, bool read_only, long tcount)
#define SPI_OPT_NONATOMIC
#define SPI_ERROR_NOATTRIBUTE
struct ErrorContextCallback * previous
void(* callback)(void *arg)
MemoryContext ecxt_per_query_memory
NullableDatum args[FLEXIBLE_ARRAY_MEMBER]
SetFunctionReturnMode returnMode
Tuplestorestate * setResult
plperl_proc_desc * prodesc
Tuplestorestate * tuple_store
unsigned long fn_refcount
plperl_interp_desc * interp
plperl_proc_desc * proc_ptr
char query_name[NAMEDATALEN]
plperl_query_desc * query_data
void ReleaseSysCache(HeapTuple tuple)
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
#define TRIGGER_FIRED_FOR_STATEMENT(event)
#define TRIGGER_FIRED_BY_DELETE(event)
#define TRIGGER_FIRED_BEFORE(event)
#define CALLED_AS_TRIGGER(fcinfo)
#define TRIGGER_FIRED_FOR_ROW(event)
#define TRIGGER_FIRED_AFTER(event)
#define TRIGGER_FIRED_BY_TRUNCATE(event)
#define TRIGGER_FIRED_BY_INSERT(event)
#define TRIGGER_FIRED_BY_UPDATE(event)
#define TRIGGER_FIRED_INSTEAD(event)
TupleDesc CreateTupleDescCopy(TupleDesc tupdesc)
#define ReleaseTupleDesc(tupdesc)
#define TupleDescAttr(tupdesc, i)
void tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc, Datum *values, bool *isnull)
Tuplestorestate * tuplestore_begin_heap(bool randomAccess, bool interXact, int maxKBytes)
void tuplestore_puttuple(Tuplestorestate *state, HeapTuple tuple)
TupleDesc lookup_rowtype_tupdesc(Oid type_id, int32 typmod)
TupleDesc lookup_rowtype_tupdesc_domain(Oid type_id, int32 typmod, bool noError)
void BeginInternalSubTransaction(const char *name)
void RollbackAndReleaseCurrentSubTransaction(void)
void ReleaseCurrentSubTransaction(void)