postgresql triggers to update GUI?

Thys Meintjes thys at netsys.co.za
Tue Nov 27 03:46:33 EST 2001


Use the PostgreSQL LISTEN, NOTIFY commands, 

Add a rule to the table that you want notifications on, something like this:
CREATE TABLE wmanlog
(
   file   INT,
   line   INT,
   type   CHAR(10),
   .......
);

CREATE RULE wmanlogupdate AS
ON INSERT TO wmanlog
DO
  NOTIFY wmanlogentry;"""

Check for NOTIFY 'events' by doing a 
query = """LISTEN wmanlogentry""" either from a thread, which in turn can 
raize a 'real' event or a timer, I use wxWindows's wxTimer to poll and 
PyGreSQL's getnotify() method to determine the type of notification 
(wmanlogentry) if any. 

greets

On Monday 26 November 2001 10:49 pm, Brian E Gallew wrote:
> "Robert Nikander" <nikander at mindspring.com> wrote ...
>
> > I am writing a python program that uses a postgresql db backend.  I
>
> would
>
> > like to update the gui whenever a change in certain tables occurs, so
>
> it
>
> > would be nice to use triggers rather than generating the 'events' when
>
> I
>
> > update the db.  That way I get cascading changes.  Does anyone know of
>
> a
>
> > python module that supports postresql triggers? ie: you can create a
> > trigger that calls a python function?  Is there another solution here
> > that I am missing?
>
> What you are looking for are asynchronous requests.  Basically, you
> make an async request, then in your GUI mainloop you peridically check
> to see if you got any results (updating the GUI if necessary).  There
> is no way to make a database trigger talk to your GUI UNLESS you are
> willing to open up a socket in the GUI, listen/process requests on it
> and have your database trigger write to that socket (don't forget to
> have error handling in there so that it doesn't crash when there's no
> one listening).




More information about the Python-list mailing list