]> granicus.if.org Git - postgresql/commitdiff
Revert removal of trigger flag from plperl function hash key. REL9_1_ALPHA2
authorTom Lane <tgl@sss.pgh.pa.us>
Sun, 31 Oct 2010 15:42:51 +0000 (11:42 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Sun, 31 Oct 2010 15:42:51 +0000 (11:42 -0400)
As noted by Jan Urbanski, this flag is in fact needed to ensure that the
function's input/result conversion functions are set up as expected.

Add a regression test to discourage anyone from making same mistake
in future.

src/pl/plperl/expected/plperl_trigger.out
src/pl/plperl/plperl.c
src/pl/plperl/sql/plperl_trigger.sql

index 8cd74cb4b99fb29960bcaa953da0e66718c160c6..bb1aed30936e04b0cef9f5230562bcdb072273b1 100644 (file)
@@ -266,3 +266,9 @@ SELECT * FROM trigger_test;
  4 | immortal
 (1 row)
 
+CREATE FUNCTION direct_trigger() RETURNS trigger AS $$
+    return;
+$$ LANGUAGE plperl;
+SELECT direct_trigger();
+ERROR:  trigger functions can only be called as triggers
+CONTEXT:  compilation of PL/Perl function "direct_trigger"
index 44becda3f32c3065e4a24fe58cf899b033e1430c..270e9f78e05c30f12eec916f7257c015b25df5be 100644 (file)
@@ -113,7 +113,7 @@ typedef struct plperl_proc_desc
 
 /**********************************************************************
  * For speedy lookup, we maintain a hash table mapping from
- * function OID + user OID to plperl_proc_desc pointers.
+ * function OID + trigger flag + user OID to plperl_proc_desc pointers.
  * The reason the plperl_proc_desc struct isn't directly part of the hash
  * entry is to simplify recovery from errors during compile_plperl_function.
  *
@@ -127,6 +127,11 @@ typedef struct plperl_proc_desc
 typedef struct plperl_proc_key
 {
        Oid                     proc_id;                                /* Function OID */
+       /*
+        * is_trigger is really a bool, but declare as Oid to ensure this struct
+        * contains no padding
+        */
+       Oid                     is_trigger;                             /* is it a trigger function? */
        Oid                     user_id;                                /* User calling the function, or 0 */
 } plperl_proc_key;
 
@@ -1955,6 +1960,7 @@ compile_plperl_function(Oid fn_oid, bool is_trigger)
 
        /* Try to find function in plperl_proc_hash */
        proc_key.proc_id = fn_oid;
+       proc_key.is_trigger = is_trigger;
        proc_key.user_id = GetUserId();
 
        proc_ptr = hash_search(plperl_proc_hash, &proc_key,
index 1e68759b0f838947536884664512b7b2c16a65cd..c47ddad3ca8712135842ac467f658755d79ebeb6 100644 (file)
@@ -128,5 +128,10 @@ FOR EACH ROW EXECUTE PROCEDURE immortal('immortal');
 
 DELETE FROM trigger_test;
 
-
 SELECT * FROM trigger_test;
+
+CREATE FUNCTION direct_trigger() RETURNS trigger AS $$
+    return;
+$$ LANGUAGE plperl;
+
+SELECT direct_trigger();