33 * procedural language
44 *
55 * IDENTIFICATION
6- * $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_comp.c,v 1.66 2003/08/08 19:19:32 tgl Exp $
6+ * $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_comp.c,v 1.67 2003/08/18 19:16:02 tgl Exp $
77 *
88 * This software is copyrighted by Jan Wieck - Hamburg.
99 *
@@ -100,16 +100,16 @@ typedef struct plpgsql_hashent
100100 */
101101static PLpgSQL_function * do_compile (FunctionCallInfo fcinfo ,
102102HeapTuple procTup ,
103- PLpgSQL_func_hashkey * hashkey );
103+ PLpgSQL_func_hashkey * hashkey );
104104static void plpgsql_compile_error_callback (void * arg );
105105static PLpgSQL_type * build_datatype (HeapTuple typeTup ,int32 typmod );
106- static void compute_function_hashkey (FmgrInfo * flinfo ,
106+ static void compute_function_hashkey (FunctionCallInfo fcinfo ,
107107Form_pg_proc procStruct ,
108- PLpgSQL_func_hashkey * hashkey );
109- static PLpgSQL_function * plpgsql_HashTableLookup (PLpgSQL_func_hashkey * func_key );
110- static void plpgsql_HashTableInsert (PLpgSQL_function * function ,
111- PLpgSQL_func_hashkey * func_key );
112- static void plpgsql_HashTableDelete (PLpgSQL_function * function );
108+ PLpgSQL_func_hashkey * hashkey );
109+ static PLpgSQL_function * plpgsql_HashTableLookup (PLpgSQL_func_hashkey * func_key );
110+ static void plpgsql_HashTableInsert (PLpgSQL_function * function ,
111+ PLpgSQL_func_hashkey * func_key );
112+ static void plpgsql_HashTableDelete (PLpgSQL_function * function );
113113
114114/*
115115 * This routine is a crock, and so is everyplace that calls it. The problem
@@ -169,7 +169,7 @@ plpgsql_compile(FunctionCallInfo fcinfo)
169169plpgsql_HashTableInit ();
170170
171171/* Compute hashkey using function signature and actual arg types */
172- compute_function_hashkey (fcinfo -> flinfo ,procStruct ,& hashkey );
172+ compute_function_hashkey (fcinfo ,procStruct ,& hashkey );
173173hashkey_valid = true;
174174
175175/* And do the lookup */
@@ -203,7 +203,7 @@ plpgsql_compile(FunctionCallInfo fcinfo)
203203 * the completed function.
204204 */
205205if (!hashkey_valid )
206- compute_function_hashkey (fcinfo -> flinfo ,procStruct ,& hashkey );
206+ compute_function_hashkey (fcinfo ,procStruct ,& hashkey );
207207
208208/*
209209 * Do the hard part.
@@ -230,7 +230,7 @@ plpgsql_compile(FunctionCallInfo fcinfo)
230230static PLpgSQL_function *
231231do_compile (FunctionCallInfo fcinfo ,
232232HeapTuple procTup ,
233- PLpgSQL_func_hashkey * hashkey )
233+ PLpgSQL_func_hashkey * hashkey )
234234{
235235Form_pg_proc procStruct = (Form_pg_proc )GETSTRUCT (procTup );
236236int functype = CALLED_AS_TRIGGER (fcinfo ) ?T_TRIGGER :T_FUNCTION ;
@@ -1711,16 +1711,25 @@ plpgsql_yyerror(const char *s)
17111711 * The hashkey is returned into the caller-provided storage at *hashkey.
17121712 */
17131713static void
1714- compute_function_hashkey (FmgrInfo * flinfo ,
1714+ compute_function_hashkey (FunctionCallInfo fcinfo ,
17151715Form_pg_proc procStruct ,
1716- PLpgSQL_func_hashkey * hashkey )
1716+ PLpgSQL_func_hashkey * hashkey )
17171717{
17181718int i ;
17191719
17201720/* Make sure any unused bytes of the struct are zero */
17211721MemSet (hashkey ,0 ,sizeof (PLpgSQL_func_hashkey ));
17221722
1723- hashkey -> funcOid = flinfo -> fn_oid ;
1723+ /* get function OID */
1724+ hashkey -> funcOid = fcinfo -> flinfo -> fn_oid ;
1725+
1726+ /* if trigger, get relation OID */
1727+ if (CALLED_AS_TRIGGER (fcinfo ))
1728+ {
1729+ TriggerData * trigdata = (TriggerData * )fcinfo -> context ;
1730+
1731+ hashkey -> trigrelOid = RelationGetRelid (trigdata -> tg_relation );
1732+ }
17241733
17251734/* get the argument types */
17261735for (i = 0 ;i < procStruct -> pronargs ;i ++ )
@@ -1737,7 +1746,7 @@ compute_function_hashkey(FmgrInfo *flinfo,
17371746if (argtypeid == ANYARRAYOID || argtypeid == ANYELEMENTOID ||
17381747argtypeid == ANYOID )
17391748{
1740- argtypeid = get_fn_expr_argtype (flinfo ,i );
1749+ argtypeid = get_fn_expr_argtype (fcinfo -> flinfo ,i );
17411750if (!OidIsValid (argtypeid ))
17421751ereport (ERROR ,
17431752(errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
@@ -1767,7 +1776,7 @@ plpgsql_HashTableInit(void)
17671776}
17681777
17691778static PLpgSQL_function *
1770- plpgsql_HashTableLookup (PLpgSQL_func_hashkey * func_key )
1779+ plpgsql_HashTableLookup (PLpgSQL_func_hashkey * func_key )
17711780{
17721781plpgsql_HashEnt * hentry ;
17731782
@@ -1782,8 +1791,8 @@ plpgsql_HashTableLookup(PLpgSQL_func_hashkey * func_key)
17821791}
17831792
17841793static void
1785- plpgsql_HashTableInsert (PLpgSQL_function * function ,
1786- PLpgSQL_func_hashkey * func_key )
1794+ plpgsql_HashTableInsert (PLpgSQL_function * function ,
1795+ PLpgSQL_func_hashkey * func_key )
17871796{
17881797plpgsql_HashEnt * hentry ;
17891798bool found ;
@@ -1805,7 +1814,7 @@ plpgsql_HashTableInsert(PLpgSQL_function * function,
18051814}
18061815
18071816static void
1808- plpgsql_HashTableDelete (PLpgSQL_function * function )
1817+ plpgsql_HashTableDelete (PLpgSQL_function * function )
18091818{
18101819plpgsql_HashEnt * hentry ;
18111820