Subject Re: Call external program with trigger
Author mspencewasunavailable
--- In firebird-support@yahoogroups.com, "Adam" <s3057043@...> wrote:
>
> --- In firebird-support@yahoogroups.com, Jocelyn Bernier
> <jbernier@> wrote:
> >
> > I know this must have been a question asked many times but
couldn't
> find
> > the answer on the net. I would like to know if it is possible to
> call an
> > external program with trigger ?
>
> Yes it is possible, but it is usually a bad idea.
>
> An external function can be written in your language of choice and
> compiled to a .dll or .so file. These functions should be
lightweight
> and must be threadsafe. You can declare them in your database,
after
> which time you can call them from normal queries or PSQL (triggers
or
> procedures).
>
> There is no technical reason that an external function could not
call
> an appropriate API call on the host OS to launch a process, but it
is
> a can of worms IMO. You need to consider resources and performance.
> You need to consider stability. You need to consider security. You
> need to realise this is using a feature in a way that is normally
> discouraged and therefore understand it may change in the future.
>
> Adam
>

And those are very big worms, indeed.

Consider using Events for this, instead. The external program
you're targeting starts, registers the fact that it wants to be
notified of particular named events and waits for a Firebird Event
to be signalled. When it is notified that the Event has occured, it
does whatever it's supposed to do, then waits again. This program
has to run all the time, of course but it's not doing anything
except waiting until the event occurs.

In the trigger, whenever you want the external program to proceed,
you say POST_EVENT <event name>;

Any worms that exist will be much smaller...

Michael D. Spence
Mockingbird Data Systems, Inc.