Re: [PATCHES] [HACKERS] statement level trigger causes pltcl, plpython SIGSEGV

2003-08-04 Thread Tom Lane
Joe Conway <[EMAIL PROTECTED]> writes:
> This patch includes pltcl and plpython, with the mentioned style issue 
> fixed. Both PLs pass their scripted tests and my simple statement level 
> trigger test.

Applied, thanks.

BTW, one other stylistic nit: I don't think comments like

/* internal error */
elog(ERROR, "unrecognized OP tg_event: %u", tdata->tg_event);

are really necessary.  In the brave new ereport world, any elog(ERROR)
call is an internal error by definition --- if it isn't, you should be
using ereport.  So the use of elog is sufficient documentation.  IMHO
anyway.

regards, tom lane

---(end of broadcast)---
TIP 4: Don't 'kill -9' the postmaster


Re: [PATCHES] [HACKERS] statement level trigger causes pltcl, plpython SIGSEGV

2003-08-04 Thread Tom Lane
Joe Conway <[EMAIL PROTECTED]> writes:
> Note that I also changed behavior in that when trigdata->tg_event 
> doesn't match anything known -- instead of pressing on with a value of 
> "UNKNOWN" it now throws an "elog(ERROR...". The previous behavior made 
> no sense to me, but you may not want to change existing behavior in this 
> way (even though it seems to me that it is a "should not happen" kind of 
> error).

Seems reasonable to me.  As a matter of style, the "unrecognized" elogs
should print the offending tg_event value; otherwise the patch looks fine.

> If this patch is acceptable, I'll make similar changes to plpython.

Please do.

regards, tom lane

---(end of broadcast)---
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to [EMAIL PROTECTED])


Re: [PATCHES] [HACKERS] statement level trigger causes pltcl, plpython SIGSEGV

2003-08-03 Thread Joe Conway
Joe Conway wrote:
I'll try to submit a patch later tonight or tomorrow morning if no one 
beats me to it.

Here's a patch for pltcl. It works for my test case:

CREATE OR REPLACE FUNCTION footrigfunc() RETURNS trigger AS 'return OK' 
LANGUAGE pltcl;
CREATE TRIGGER footrig BEFORE INSERT OR UPDATE OR DELETE ON foo FOR EACH 
STATEMENT EXECUTE PROCEDURE footrigfunc();
insert into foo values(11,'cat99',1.89);
delete from foo where f0 = 11;

I also ran the "runtest" script in pl/tcl/test -- it said:
 Running test queries 
Tests passed O.K.
Note that I also changed behavior in that when trigdata->tg_event 
doesn't match anything known -- instead of pressing on with a value of 
"UNKNOWN" it now throws an "elog(ERROR...". The previous behavior made 
no sense to me, but you may not want to change existing behavior in this 
way (even though it seems to me that it is a "should not happen" kind of 
error).

If this patch is acceptable, I'll make similar changes to plpython. If 
not, let me know what to change.

Thanks,

Joe
Index: src/pl/tcl/pltcl.c
===
RCS file: /opt/src/cvs/pgsql-server/src/pl/tcl/pltcl.c,v
retrieving revision 1.74
diff -c -r1.74 pltcl.c
*** src/pl/tcl/pltcl.c  4 Aug 2003 00:43:33 -   1.74
--- src/pl/tcl/pltcl.c  4 Aug 2003 05:36:12 -
***
*** 708,770 
else if (TRIGGER_FIRED_AFTER(trigdata->tg_event))
Tcl_DStringAppendElement(&tcl_cmd, "AFTER");
else
!   Tcl_DStringAppendElement(&tcl_cmd, "UNKNOWN");
  
/* The level part of the event for TG_level */
if (TRIGGER_FIRED_FOR_ROW(trigdata->tg_event))
Tcl_DStringAppendElement(&tcl_cmd, "ROW");
else if (TRIGGER_FIRED_FOR_STATEMENT(trigdata->tg_event))
Tcl_DStringAppendElement(&tcl_cmd, "STATEMENT");
-   else
-   Tcl_DStringAppendElement(&tcl_cmd, "UNKNOWN");
  
!   /* Build the data list for the trigtuple */
!   pltcl_build_tuple_argument(trigdata->tg_trigtuple,
!  tupdesc, &tcl_trigtup);
! 
!   /*
!* Now the command part of the event for TG_op and data for NEW and
!* OLD
!*/
!   if (TRIGGER_FIRED_BY_INSERT(trigdata->tg_event))
!   {
!   Tcl_DStringAppendElement(&tcl_cmd, "INSERT");
  
-   Tcl_DStringAppendElement(&tcl_cmd, Tcl_DStringValue(&tcl_trigtup));
Tcl_DStringAppendElement(&tcl_cmd, "");
- 
-   rettup = trigdata->tg_trigtuple;
-   }
-   else if (TRIGGER_FIRED_BY_DELETE(trigdata->tg_event))
-   {
-   Tcl_DStringAppendElement(&tcl_cmd, "DELETE");
- 
Tcl_DStringAppendElement(&tcl_cmd, "");
-   Tcl_DStringAppendElement(&tcl_cmd, Tcl_DStringValue(&tcl_trigtup));
  
!   rettup = trigdata->tg_trigtuple;
!   }
!   else if (TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event))
!   {
!   Tcl_DStringAppendElement(&tcl_cmd, "UPDATE");
! 
!   pltcl_build_tuple_argument(trigdata->tg_newtuple,
!  tupdesc, 
&tcl_newtup);
! 
!   Tcl_DStringAppendElement(&tcl_cmd, Tcl_DStringValue(&tcl_newtup));
!   Tcl_DStringAppendElement(&tcl_cmd, Tcl_DStringValue(&tcl_trigtup));
! 
!   rettup = trigdata->tg_newtuple;
}
else
!   {
!   Tcl_DStringAppendElement(&tcl_cmd, "UNKNOWN");
! 
!   Tcl_DStringAppendElement(&tcl_cmd, Tcl_DStringValue(&tcl_trigtup));
!   Tcl_DStringAppendElement(&tcl_cmd, Tcl_DStringValue(&tcl_trigtup));
! 
!   rettup = trigdata->tg_trigtuple;
!   }
  
memcpy(&Warn_restart, &save_restart, sizeof(Warn_restart));
Tcl_DStringFree(&tcl_trigtup);
--- 708,785 
else if (TRIGGER_FIRED_AFTER(trigdata->tg_event))
Tcl_DStringAppendElement(&tcl_cmd, "AFTER");
else
!   /* internal error */
!   elog(ERROR, "unrecognized WHEN tg_event");
  
/* The level part of the event for TG_level */
if (TRIGGER_FIRED_FOR_ROW(trigdata->tg_event))
+   {
Tcl_DStringAppendElement(&tcl_cmd, "ROW");
+ 
+   /* Build the data list for the trigtuple */
+   pltcl_build_tuple_argument(trigdata->tg_trigtuple,
+  tupdesc, 
&tcl_trigtup);
+ 
+   /*
+* Now the command part of the event for TG_op and data for NEW and
+* OLD
+*/
+   if (TRIGGER_FIRED_BY_INSERT(trigdata->tg_event))
+   {
+   Tcl_DStringAppendElement(&tcl_cmd, "INSERT");
+ 
+   Tcl_DStringAppendElement(&tcl_cmd, 
Tcl_DStringValue(&tcl_trigtup));
+   Tcl_DStringAppendElement(&tcl_c