pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: hook <hook@kcp.com>
To: pgsql-sql@postgresql.org
Subject: I'm baffled
Date: Tue, 18 May 2004 11:19:16 -0500
Message-ID: <40AA3784.4060303@kcp.com> (raw)

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@kcp.com     < /tmp/newMsg");
  return(0);
}




Message-ID: <40AA3784.4060303@kcp.com>
Permalink:  ../40AA3784.4060303@kcp.com/
Also on:    postgresql.org/message-id/40AA3784.4060303@kcp.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: hook@kcp.com
  Subject: Re: I'm baffled
  In-Reply-To: <40AA3784.4060303@kcp.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox