Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

Notifications and Triggers

"Observer" base class for trigger notifications. More...

Functions

int pqxx::connection_base::get_notifs ()
 Check for pending trigger notifications and take appropriate action.
int pqxx::connection_base::await_notification ()
 Wait for a trigger notification notification to come in.
int pqxx::connection_base::await_notification (long seconds, long microseconds)
 Wait for a trigger notification to come in, or for given timeout to pass.

Detailed Description

"Observer" base class for trigger notifications.

To listen on a database trigger, derive your own class from trigger and define its function call operator to perform whatever action you wish to take when the given trigger arrives. Then create an object of that class and pass it to your connection. DO NOT set triggers directly through SQL, or they won't be restored when your connection fails--and you'll have no way to notice.

Trigger notifications never arrive inside a transaction. Therefore, you are free to open a transaction of your own inside your trigger's function invocation operator.

Notifications for your trigger may arrive anywhere within libpqxx code, but be aware that PostgreSQL defers notifications occurring inside transactions. (This was done for excellent reasons; just think about what happens if the transaction where you happen to handle an incoming notification is later rolled back for other reasons). So if you're keeping a transaction open, don't expect any of your triggers on the same connection to be notified.

Multiple triggers on the same connection may have the same name. An incoming notification is processed by invoking all triggers (zero or more) of the same name.


Function Documentation

int pqxx::connection_base::await_notification long  seconds,
long  microseconds
[inherited]
 

Wait for a trigger notification to come in, or for given timeout to pass.

The wait may also be terminated by other events, such as the connection to the backend failing. Any pending or received notifications are processed as part of the call.

Returns:
Number of notifications processed

int pqxx::connection_base::await_notification  )  [inherited]
 

Wait for a trigger notification notification to come in.

The wait may also be terminated by other events, such as the connection to the backend failing. Any pending or received notifications are processed as part of the call.

Returns:
Number of notifications processed

int pqxx::connection_base::get_notifs  )  [inherited]
 

Check for pending trigger notifications and take appropriate action.

All notifications found pending at call time are processed by finding any matching triggers and invoking those. If no triggers matched the notification string, none are invoked but the notification is considered processed.

Exceptions thrown by client-registered trigger handlers are reported, but not passed on outside this function.

Returns:
Number of notifications processed


Generated on Mon Oct 3 20:29:02 2005 for libpqxx by  doxygen 1.4.2