NOTIFY/LISTEN why is not a callback as notice processing.
NOTIFY/LISTEN why is not a callback as notice processing.
От:
"Filonenko Michael" <filonenko.mikhail@gmail.com>
Дата:
Hello. I create simple mechanism to inform user about something in database triggers. In my front-end I use PQsetNoticeReceiver, and display messages in QTextEdit. I think about multi-user environment. I read about NOTIFY/LISTEN, but find no callback mechanism. Is it planning? -- With best regards, Michael Filonenko.
Re: NOTIFY/LISTEN why is not a callback as notice processing.
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
"Filonenko Michael" writes: > I create simple mechanism to inform user about something in database > triggers. In my front-end I use PQsetNoticeReceiver, and display messages > in QTextEdit. > I think about multi-user environment. I read about NOTIFY/LISTEN, but find > no callback mechanism. Is it planning? Not in libpq. libpq is just a passive library, it can't cause actions to happen when you aren't calling it. So there's no point in a callback: you might as well just test for occurrences of a NOTIFY at times when you're prepared to handle it. regards, tom lane
Re: NOTIFY/LISTEN why is not a callback as notice processing.
От:
"Daniel Verite" <daniel@manitou-mail.org>
Дата:
Filonenko Michael wrote: > I create simple mechanism to inform user about something in database > triggers. In my front-end I use PQsetNoticeReceiver, and display messages > in QTextEdit. > I think about multi-user environment. I read about NOTIFY/LISTEN, but find > no callback mechanism. Is it planning? Not sure what the multi-user environment implies, but since you're using Qt, you're probably interested in getting a Qt signal when a db notification arrives. It turns out it's not hard to do: before calling LISTEN, instantiate a QSocketNotifier object bound to the socket of the libpq connection, and connect its activated() signal to a slot. In this slot, your code can deal with the notification at the libpq level with PQconsumeInput() and PQnotifies(), do your own processing, and just return. With this method, you don't have any need for a callback or managing your own loop: it is Qt's event loop that calls the slot, just as it does for GUI-related events. Best regards, -- Daniel PostgreSQL-powered mail user agent and storage: http://www.manitou-mail.org
Re: NOTIFY/LISTEN why is not a callback as notice processing.
От:
Steve Atkins <steve@blighty.com>
Дата:
On Nov 10, 2010, at 4:30 PM, Daniel Verite wrote: > Filonenko Michael wrote: > >> I create simple mechanism to inform user about something in database >> triggers. In my front-end I use PQsetNoticeReceiver, and display messages >> in QTextEdit. >> I think about multi-user environment. I read about NOTIFY/LISTEN, but find >> no callback mechanism. Is it planning? > > Not sure what the multi-user environment implies, but since you're using Qt, > you're probably interested in getting a Qt signal when a db notification > arrives. It turns out it's not hard to do: before calling LISTEN, instantiate > a QSocketNotifier object bound to the socket of the libpq connection, and > connect its activated() signal to a slot. In this slot, your code can deal > with the notification at the libpq level with PQconsumeInput() and > PQnotifies(), do your own processing, and just return. > With this method, you don't have any need for a callback or managing your own > loop: it is Qt's event loop that calls the slot, just as it does for > GUI-related events. It's even easier than that - Qt supports listen/notify directly. QSqlDriver::subscribeToNotification(), and connect the the notification() signal. Cheers, Steve
Re: NOTIFY/LISTEN why is not a callback as notice processing.
От:
Vick Khera <vivek@khera.org>
Дата:
On Wed, Nov 10, 2010 at 5:20 PM, Tom Lane wrote: > Not in libpq. libpq is just a passive library, it can't cause actions > to happen when you aren't calling it. So there's no point in a > callback: you might as well just test for occurrences of a NOTIFY at > times when you're prepared to handle it. > On my systems where I use them more or less as "wakeup and do work" signals, I just do a select() call on the connection socket. When the signal arrives, the socket becomes readable, and then I just query for the notification.
Re: NOTIFY/LISTEN why is not a callback as notice processing.
От:
Михаил Филоненко<filonenko.mikhail@gmail.com>
Дата:
Thanks. But also I want to use postgresql and gtk with python or with c. I think, I need to make something like QSocketNotifier with callbacks instead of signals/slots.
Well, why does libpq accumulate notifi and commit developer to create loop?
select(....)
PQconsumeInput(conn)while ((notify = PQnotifies(conn)) != NULL)
// show notify
Interface for notice processing provided by libpq is simpler. Notice and notifies very
receiver(connection, message) {// show notify
}PQsetNoticeReceiver(receiver);
--
With best regards, Michael Filonenko