I'm baffled

From: hook <hook(at)kcp(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: I'm baffled
Date: 2004-05-18 16:19:16
Message-ID: 40AA3784.4060303@kcp.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

I have a couple of 'c' object files that send mail when ever there in an
insert or delete to specified tables.
The problem is that I get the mail message even if the insert fails!

what am I doing wrong?

thanks

The function;
create function insert_r1(text, text, text, text) returns int4
as '/var/pgsql/insert_r1.so' LANGUAGE 'c' ;
the rule:
create rule partmaster_I as
on insert to partmaster
do select insert_R1(new.afpn, 'partmaster(insert)','','') as answer;

the 'c' module:
# include "internal/postgres_fe.h"
# include <string.h>
# include <unistd.h>

int insert_r1(text *arg1, text *arg2, text *arg3, text *arg4)
{
char *table, *key, *mesg, *user;
char host[20];
FILE *fp;

arg1->vl_dat[arg1->vl_len - VARHDRSZ] = '\0';
arg2->vl_dat[arg2->vl_len - VARHDRSZ] = '\0';
arg3->vl_dat[arg3->vl_len - VARHDRSZ] = '\0';
arg4->vl_dat[arg4->vl_len - VARHDRSZ] = '\0';

key = strdup(arg1->vl_dat);
table = strdup(arg2->vl_dat);
mesg = strdup(arg3->vl_dat);
user = strdup(arg4->vl_dat);

gethostname(host, sizeof(host));
system(" cat /tmp/newMsg >> /tmp/newMsg.arc");
if ( (fp = fopen("/tmp/newMsg", "w+") ) == NULL)
return(-1);
fprintf(fp, "%s:: %s:(%s) Approval requested - %s %s\n",
host,table,key,mesg,user);
fclose (fp);

system("Mail -s \"Bmss \" hook(at)kcp(dot)com < /tmp/newMsg");
return(0);
}

Browse pgsql-sql by date

  From Date Subject
Next Message Hans de Bruin 2004-05-18 16:56:45 Re: How to speed up a time dimension query
Previous Message Bruno Wolff III 2004-05-18 16:12:56 Re: Very slow search using basic pattern matching