Thread: NOTIFY/LISTEN Using Embedded SQL (ecpg)
[cross posted from comp.databases.postgresql.general] I seem to have painted myself into a corner, technologically speaking. I am implementing a database using embedded SQL, and PostgreSQL 6.5.3 as the backend. The problem is that I would like to use the NOTIFY feature, but the only way I've found of doing this from within a C program is to use the 'PQnotifies()' function, which requires a PGconn connection its first parameter. ESQL doesn't provide this connection information as far as I can tell. So, it appears that I can set up my program to LISTEN or UNLISTEN using embedded SQL, but I can't get a notification when it's sent. Or so I think. _Is_ there a way to get the libpq connection info from the ESQL CONNECT call? Does anyone have a suggestion (other than completely rewriting my application in libpq calls)? Pointers to any examples of how this is done would be especially helpful, but any hints would be appreciated. Here's an example that may help illustrate my problem: int main() { PGconn *conn = NULL; EXEC SQL CONNECT database ; EXEC SQL LISTEN foo_changed ; for( ; /* EVER */ ; ) { if( PQnotifies(conn) ) /* conn is still NULL */ printf("Something happened\n" ) ; ..... } }
From: "Craig Orsinger" <cjorsinger@m5.earthlink_net.invalid> To: <pgsql-general@postgresql.org> Sent: Tuesday, May 22, 2001 6:08 PM Subject: [GENERAL] NOTIFY/LISTEN Using Embedded SQL (ecpg) > [cross posted from comp.databases.postgresql.general] > > So, it appears that I can set up my program to LISTEN or > UNLISTEN using embedded SQL, but I can't get a notification when > it's sent. Or so I think. _Is_ there a way to get the libpq connection info > from the ESQL CONNECT call? > > Does anyone have a suggestion (other than completely rewriting > my application in libpq calls)? Pointers to any examples of how > this is done would be especially helpful, but any hints would be > appreciated. Can you not just wrap up the libpq stuff in it's own module? A "LISTEN X" doesn't have to be on any particular connection. Don't know whether opening another connection per program is practical for you. - Richard Huxton
"Craig Orsinger" <cjorsinger@m5.earthlink_net.invalid> writes: > So, it appears that I can set up my program to LISTEN or > UNLISTEN using embedded SQL, but I can't get a notification when > it's sent. Or so I think. _Is_ there a way to get the libpq connection info > from the ESQL CONNECT call? Seems like there should be, if there isn't. NOTIFY isn't the only thing you might want to grab the PGconn object for. regards, tom lane