mirror of
https://github.com/postgres/postgres.git
synced 2025-07-27 12:41:57 +03:00
Add SysCacheGetAttrNotNull for guaranteed not-null attrs
When extracting an attr from a cached tuple in the syscache with SysCacheGetAttr the isnull parameter must be checked in case the attr cannot be NULL. For cases when this is known beforehand, a wrapper is introduced which perform the errorhandling internally on behalf of the caller, invoking an elog in case of a NULL attr. Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Reviewed-by: Peter Eisentraut <peter.eisentraut@enterprisedb.com> Reviewed-by: David Rowley <dgrowleyml@gmail.com> Discussion: https://postgr.es/m/AD76405E-DB45-46B6-941F-17B1EB3A9076@yesql.se
This commit is contained in:
@ -2915,10 +2915,8 @@ compile_plperl_function(Oid fn_oid, bool is_trigger, bool is_event_trigger)
|
||||
* we do not use a named subroutine so that we can call directly
|
||||
* through the reference.
|
||||
************************************************************/
|
||||
prosrcdatum = SysCacheGetAttr(PROCOID, procTup,
|
||||
Anum_pg_proc_prosrc, &isnull);
|
||||
if (isnull)
|
||||
elog(ERROR, "null prosrc");
|
||||
prosrcdatum = SysCacheGetAttrNotNull(PROCOID, procTup,
|
||||
Anum_pg_proc_prosrc);
|
||||
proc_source = TextDatumGetCString(prosrcdatum);
|
||||
|
||||
/************************************************************
|
||||
|
@ -271,7 +271,6 @@ do_compile(FunctionCallInfo fcinfo,
|
||||
bool is_dml_trigger = CALLED_AS_TRIGGER(fcinfo);
|
||||
bool is_event_trigger = CALLED_AS_EVENT_TRIGGER(fcinfo);
|
||||
Datum prosrcdatum;
|
||||
bool isnull;
|
||||
char *proc_source;
|
||||
HeapTuple typeTup;
|
||||
Form_pg_type typeStruct;
|
||||
@ -296,10 +295,7 @@ do_compile(FunctionCallInfo fcinfo,
|
||||
* cannot be invoked recursively, so there's no need to save and restore
|
||||
* the static variables used here.
|
||||
*/
|
||||
prosrcdatum = SysCacheGetAttr(PROCOID, procTup,
|
||||
Anum_pg_proc_prosrc, &isnull);
|
||||
if (isnull)
|
||||
elog(ERROR, "null prosrc");
|
||||
prosrcdatum = SysCacheGetAttrNotNull(PROCOID, procTup, Anum_pg_proc_prosrc);
|
||||
proc_source = TextDatumGetCString(prosrcdatum);
|
||||
plpgsql_scanner_init(proc_source);
|
||||
|
||||
|
@ -324,10 +324,8 @@ PLy_procedure_create(HeapTuple procTup, Oid fn_oid, bool is_trigger)
|
||||
/*
|
||||
* get the text of the function.
|
||||
*/
|
||||
prosrcdatum = SysCacheGetAttr(PROCOID, procTup,
|
||||
Anum_pg_proc_prosrc, &isnull);
|
||||
if (isnull)
|
||||
elog(ERROR, "null prosrc");
|
||||
prosrcdatum = SysCacheGetAttrNotNull(PROCOID, procTup,
|
||||
Anum_pg_proc_prosrc);
|
||||
procSource = TextDatumGetCString(prosrcdatum);
|
||||
|
||||
PLy_procedure_compile(proc, procSource);
|
||||
|
@ -1454,7 +1454,6 @@ compile_pltcl_function(Oid fn_oid, Oid tgreloid,
|
||||
Form_pg_type typeStruct;
|
||||
char proc_internal_args[33 * FUNC_MAX_ARGS];
|
||||
Datum prosrcdatum;
|
||||
bool isnull;
|
||||
char *proc_source;
|
||||
char buf[48];
|
||||
Tcl_Interp *interp;
|
||||
@ -1673,10 +1672,8 @@ compile_pltcl_function(Oid fn_oid, Oid tgreloid,
|
||||
/************************************************************
|
||||
* Add user's function definition to proc body
|
||||
************************************************************/
|
||||
prosrcdatum = SysCacheGetAttr(PROCOID, procTup,
|
||||
Anum_pg_proc_prosrc, &isnull);
|
||||
if (isnull)
|
||||
elog(ERROR, "null prosrc");
|
||||
prosrcdatum = SysCacheGetAttrNotNull(PROCOID, procTup,
|
||||
Anum_pg_proc_prosrc);
|
||||
proc_source = TextDatumGetCString(prosrcdatum);
|
||||
UTF_BEGIN;
|
||||
Tcl_DStringAppend(&proc_internal_body, UTF_E2U(proc_source), -1);
|
||||
|
Reference in New Issue
Block a user