52 return "<unknown procedure>";
71 bool use_cache = !(is_trigger && fn_rel ==
InvalidOid);
80 elog(
ERROR,
"cache lookup failed for function %u", fn_oid);
144 rv =
snprintf(procName,
sizeof(procName),
145 "__plpython_procedure_%s_%u",
148 if (rv >=
sizeof(procName) || rv < 0)
149 elog(
ERROR,
"procedure name would overrun buffer");
152 for (ptr = procName; *ptr; ptr++)
154 if (!((*ptr >=
'A' && *ptr <=
'Z') ||
155 (*ptr >=
'a' && *ptr <=
'z') ||
156 (*ptr >=
'0' && *ptr <=
'9')))
162 "PL/Python function",
172 Datum protrftypes_datum;
183 proc->
fn_readonly = (procStruct->provolatile != PROVOLATILE_VOLATILE);
184 proc->
is_setof = procStruct->proretset;
185 proc->
is_procedure = (procStruct->prokind == PROKIND_PROCEDURE);
191 proc->
langid = procStruct->prolang;
193 Anum_pg_proc_protrftypes,
208 Oid rettype = procStruct->prorettype;
214 elog(
ERROR,
"cache lookup failed for type %u", rettype);
218 if (rvTypeStruct->typtype == TYPTYPE_PSEUDO)
220 if (rettype == VOIDOID ||
221 rettype == RECORDOID)
223 else if (rettype == TRIGGEROID || rettype == EVENT_TRIGGEROID)
225 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
226 errmsg(
"trigger functions can only be called as triggers")));
229 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
230 errmsg(
"PL/Python functions cannot return type %s",
257 if (procStruct->pronargs)
274 for (
i = 0;
i < total;
i++)
276 if (modes[
i] != PROARGMODE_OUT &&
277 modes[
i] != PROARGMODE_TABLE)
286 for (
i = pos = 0;
i < total;
i++)
292 (modes[
i] == PROARGMODE_OUT ||
293 modes[
i] == PROARGMODE_TABLE))
296 Assert(
types[
i] == procStruct->proargtypes.values[pos]);
305 if (argTypeStruct->typtype == TYPTYPE_PSEUDO)
307 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
308 errmsg(
"PL/Python functions cannot accept type %s",
329 Anum_pg_proc_prosrc);
354 PyObject *crv = NULL;
374 crv = PyRun_String(msrc, Py_file_input, proc->
globals, NULL);
388 if (clen < 0 || clen >=
sizeof(call))
389 elog(
ERROR,
"string would overflow buffer");
390 proc->
code = Py_CompileString(call,
"<string>", Py_eval_input);
391 if (proc->
code != NULL)
396 PLy_elog(
ERROR,
"could not compile PL/Python function \"%s\"",
399 PLy_elog(
ERROR,
"could not compile anonymous PL/Python code block");
405 Py_XDECREF(proc->
code);
440 mlen = (strlen(src) * 2) + strlen(
name) + 16;
444 Assert(plen >= 0 && plen < mlen);
451 if (*sp ==
'\r' && *(sp + 1) ==
'\n')
454 if (*sp ==
'\n' || *sp ==
'\r')
467 if (mp > (mrc + mlen))
468 elog(
FATAL,
"buffer overrun in PLy_procedure_munge_source");
#define TextDatumGetCString(d)
#define Assert(condition)
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)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
int get_func_arg_info(HeapTuple procTup, Oid **p_argtypes, char ***p_argnames, char **p_argmodes)
#define HeapTupleIsValid(tuple)
#define HeapTupleHeaderGetRawXmin(tup)
bool ItemPointerEquals(ItemPointer pointer1, ItemPointer pointer2)
char * pstrdup(const char *in)
void pfree(void *pointer)
MemoryContext TopMemoryContext
void * palloc0(Size size)
char * MemoryContextStrdup(MemoryContext context, const char *string)
void MemoryContextDelete(MemoryContext context)
void MemoryContextSetIdentifier(MemoryContext context, const char *id)
#define AllocSetContextCreate
#define ALLOCSET_DEFAULT_SIZES
List * oid_array_to_list(Datum datum)
FormData_pg_proc * Form_pg_proc
FormData_pg_type * Form_pg_type
PyObject * PLy_interp_globals
void init_procedure_caches(void)
static PLyProcedure * PLy_procedure_create(HeapTuple procTup, Oid fn_oid, bool is_trigger)
static char * PLy_procedure_munge_source(const char *name, const char *src)
char * PLy_procedure_name(PLyProcedure *proc)
PLyProcedure * PLy_procedure_get(Oid fn_oid, Oid fn_rel, bool is_trigger)
static bool PLy_procedure_valid(PLyProcedure *proc, HeapTuple procTup)
static HTAB * PLy_procedure_cache
void PLy_procedure_compile(PLyProcedure *proc, const char *src)
void PLy_procedure_delete(PLyProcedure *proc)
struct PLyProcedureKey PLyProcedureKey
struct PLyProcedureEntry PLyProcedureEntry
void PLy_output_setup_func(PLyObToDatum *arg, MemoryContext arg_mcxt, Oid typeOid, int32 typmod, PLyProcedure *proc)
void PLy_input_setup_func(PLyDatumToOb *arg, MemoryContext arg_mcxt, Oid typeOid, int32 typmod, PLyProcedure *proc)
static Datum ObjectIdGetDatum(Oid X)
MemoryContextSwitchTo(old_ctx)
void ReleaseSysCache(HeapTuple tuple)
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Datum SysCacheGetAttrNotNull(int cacheId, HeapTuple tup, AttrNumber attributeNumber)