From 15f55cc38a82dfa3d7898a7c30a303b1b3e87dc3 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Tue, 1 Feb 2011 22:53:40 +0200 Subject: Add validator to PL/Python Jan UrbaƄski, reviewed by Hitoshi Harada --- src/pl/plpython/plpython.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'src/pl/plpython/plpython.c') diff --git a/src/pl/plpython/plpython.c b/src/pl/plpython/plpython.c index aafe556c04e..fbfeb2c9f16 100644 --- a/src/pl/plpython/plpython.c +++ b/src/pl/plpython/plpython.c @@ -251,15 +251,18 @@ typedef struct PLyResultObject #if PY_MAJOR_VERSION >= 3 /* Use separate names to avoid clash in pg_pltemplate */ +#define plpython_validator plpython3_validator #define plpython_call_handler plpython3_call_handler #define plpython_inline_handler plpython3_inline_handler #endif /* exported functions */ +Datum plpython_validator(PG_FUNCTION_ARGS); Datum plpython_call_handler(PG_FUNCTION_ARGS); Datum plpython_inline_handler(PG_FUNCTION_ARGS); void _PG_init(void); +PG_FUNCTION_INFO_V1(plpython_validator); PG_FUNCTION_INFO_V1(plpython_call_handler); PG_FUNCTION_INFO_V1(plpython_inline_handler); @@ -437,6 +440,42 @@ plpython_return_error_callback(void *arg) errcontext("while creating return value"); } +static bool +PLy_procedure_is_trigger(Form_pg_proc procStruct) +{ + return (procStruct->prorettype == TRIGGEROID || + (procStruct->prorettype == OPAQUEOID && + procStruct->pronargs == 0)); +} + +Datum +plpython_validator(PG_FUNCTION_ARGS) +{ + Oid funcoid = PG_GETARG_OID(0); + HeapTuple tuple; + Form_pg_proc procStruct; + bool is_trigger; + + if (!check_function_bodies) + { + PG_RETURN_VOID(); + } + + /* Get the new function's pg_proc entry */ + tuple = SearchSysCache1(PROCOID, ObjectIdGetDatum(funcoid)); + if (!HeapTupleIsValid(tuple)) + elog(ERROR, "cache lookup failed for function %u", funcoid); + procStruct = (Form_pg_proc) GETSTRUCT(tuple); + + is_trigger = PLy_procedure_is_trigger(procStruct); + + ReleaseSysCache(tuple); + + PLy_procedure_get(funcoid, is_trigger); + + PG_RETURN_VOID(); +} + Datum plpython_call_handler(PG_FUNCTION_ARGS) { -- cgit v1.2.3