>>>>> "J" == Jeremy Henty <jeremy / chaos.org.uk> writes:

J> I specifically want a FOR EACH STATEMENT trigger .

 I hope that know that, in this case, you don't have access to old, new and
 normally you must *ONLY* return false

J> next_version_will_support_this? ? "Cool!" : "What needs to be done to
J> support this?"

vg% diff -u plruby.c~ plruby.c
--- plruby.c~	2005-06-06 17:38:38.000000000 +0200
+++ plruby.c	2005-10-05 15:33:54.000000000 +0200
@@ -1203,24 +1203,32 @@
         rb_raise(pl_ePLruby, "unknown LEVEL event (%u)", trigdata->tg_event);
     }
 
+    tg_old = Qnil;
+    tg_new = Qnil;
+    rettup = NULL;
     if (TRIGGER_FIRED_BY_INSERT(trigdata->tg_event)) {
         rb_hash_aset(TG, rb_str_freeze_new2("op"), INT2FIX(TG_INSERT));
-        tg_new = plruby_build_tuple(trigdata->tg_trigtuple, tupdesc, RET_HASH);
-        tg_old = rb_hash_new();
-        rettup = trigdata->tg_trigtuple;
+        if (TRIGGER_FIRED_FOR_ROW(trigdata->tg_event)) {
+            tg_new = plruby_build_tuple(trigdata->tg_trigtuple, tupdesc, RET_HASH);
+            tg_old = rb_hash_new();
+            rettup = trigdata->tg_trigtuple;
+        }
     }
     else if (TRIGGER_FIRED_BY_DELETE(trigdata->tg_event)) {
         rb_hash_aset(TG, rb_str_freeze_new2("op"), INT2FIX(TG_DELETE));
-        tg_old = plruby_build_tuple(trigdata->tg_trigtuple, tupdesc, RET_HASH);
-        tg_new = rb_hash_new();
-
-        rettup = trigdata->tg_trigtuple;
+        if (TRIGGER_FIRED_FOR_ROW(trigdata->tg_event)) {
+            tg_old = plruby_build_tuple(trigdata->tg_trigtuple, tupdesc, RET_HASH);
+            tg_new = rb_hash_new();
+            rettup = trigdata->tg_trigtuple;
+        }
     }
     else if (TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event)) {
         rb_hash_aset(TG, rb_str_freeze_new2("op"), INT2FIX(TG_UPDATE)); 
-        tg_new = plruby_build_tuple(trigdata->tg_newtuple, tupdesc, RET_HASH);
-        tg_old = plruby_build_tuple(trigdata->tg_trigtuple, tupdesc, RET_HASH);
-        rettup = trigdata->tg_newtuple;
+        if (TRIGGER_FIRED_FOR_ROW(trigdata->tg_event)) {
+            tg_new = plruby_build_tuple(trigdata->tg_newtuple, tupdesc, RET_HASH);
+            tg_old = plruby_build_tuple(trigdata->tg_trigtuple, tupdesc, RET_HASH);
+            rettup = trigdata->tg_newtuple;
+        }
     }
     else {
         rb_raise(pl_ePLruby, "unknown OP event (%u)", trigdata->tg_event);
@@ -1276,6 +1284,10 @@
         break;
     }
 
+    if (!TRIGGER_FIRED_FOR_ROW(trigdata->tg_event)) {
+        rb_raise(pl_ePLruby, "Invalid return value for per-statement trigger");
+    }
+
     modattrs = ALLOCA_N(int, tupdesc->natts);
     modvalues = ALLOCA_N(Datum, tupdesc->natts);
     for (i = 0; i < tupdesc->natts; i++) {
svg% 



Guy Decoux