Skip site navigation (1) Skip section navigation (2)

Re: Using C functions with triggers

From: jtv <jtv(at)xs4all(dot)nl>
To: Kenny Carruthers <pgmail(at)kennyc(dot)com>
Cc: pgsql-interfaces(at)postgresql(dot)org
Subject: Re: Using C functions with triggers
Date: 2002-05-06 20:35:37
Message-ID: 20020506223537.C4114@xs4all.nl (view raw or flat)
Thread:
Lists: pgsql-interfaces
On Mon, May 06, 2002 at 12:53:47AM -0700, Kenny Carruthers wrote:
> 
>     I have an application that uses libpq to communicate with a database.
> From inside my application, I would like to define a 'trigger' and specify a
> function that is in my application as the 'trigger func' parameter. (This is
> all in C) Is this even possible? If not, how would one go about setting up
> such a callback system? What I want is to be able to define triggers at
> runtime from my application, and have different functions get executed when
> the trigger fires. 
 
Only three worries there:

1. The trigger will not arrive while you're in the middle of a transaction.
(Not a bug, pretty smart choice when you think about it).  So if libpq
finds that your trigger gets notified but you've still got a transaction
going on that connection, it will defer delivery of the trigger until
after you've finished (committed or aborted) the transaction.

2. You'll need to poll for the trigger, ie. it won't arrive asynchronously
eg. while you're off executing some non-db-related loop somewhere.

3. If you sit still for long enough without doing anything, you might
lose your connection and have to reconnect at some inconvenient time.
Not that that can't happen otherwise, but for long-running programs it
might be an issue.

If you're into C++ you may want to look at the Trigger class in libpqxx,
my alternative C++ API to PostgreSQL, which hides this stuff behind a
simple callback interface.  (I followup to questions for free, but you 
get hit with advertisements in return ;-)   It's available from my home
page at http://members.ams.chello.nl/j.vermeulen31/proj-libpqxx.html


Jeroen


In response to

pgsql-interfaces by date

Next:From: Nigel J. AndrewsDate: 2002-05-06 21:09:25
Subject: Re: Schemas: status report, call for developers
Previous:From: Tom LaneDate: 2002-05-06 19:51:18
Subject: Re: Schemas: status report, call for developers

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group