Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2003
    Posts
    42

    Unanswered: how to watch for changes in a table?

    Hi All!

    I would like to write CLI program that can watch for a state change
    of a table, i.e. when a row is inserted, updated or delete. Let's say I have a queue stored in a single table and I would like my program to watch for queue state changes and display them to the user in a GUI. Of course the program can pull for changes in a loop and display the queue state in every iteration but that is quite clumsy. Is there a way for my CLI program to be notified or to be woken up when there is any change in the table?

    What DB2 feature can be used for this?

    Do you guys have any ideas?

    Thanks in advance.

    Alexander

  2. #2
    Join Date
    May 2003
    Location
    USA
    Posts
    5,737
    I would look at using triggers to update another status table any time the table in question has been changed. You could log the exact timestamp the table has been inserted, updated or deleted, as well as any other information you needed.
    M. A. Feldman
    IBM Certified DBA on DB2 for Linux, UNIX, and Windows
    IBM Certified DBA on DB2 for z/OS and OS/390

  3. #3
    Join Date
    Nov 2003
    Posts
    42
    Thanks for your reply!

    Actually my problem is not recording the changes but to have my ODBC/CLI program being notified that something has been changed. In that way the program does not need to continuesly query the database and check for changes. I am not sure what I want is possible but there might be some trick I do not know about

  4. #4
    Join Date
    Aug 2001
    Location
    UK
    Posts
    4,650
    You can create a non-SQL UDF (in C, Java etc) that will 'alert' your program ....
    For eg, write a file to a directory and your CLI program can get activated when the file is found.

    Inside the trigger, call the UDF

    VALUES(WRITEFILEUDF())


    For information on creating UDFs, refer Appl Development manuals


    HTH

    Sathyaram
    Visit the new-look IDUG Website , register to gain access to the excellent content.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •