If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > how to watch for changes in a table?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-01-04, 10:50
akaraivanov akaraivanov is offline
Registered User
 
Join Date: Nov 2003
Posts: 42
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
Reply With Quote
  #2 (permalink)  
Old 07-01-04, 11:27
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
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
Reply With Quote
  #3 (permalink)  
Old 07-01-04, 11:50
akaraivanov akaraivanov is offline
Registered User
 
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
Reply With Quote
  #4 (permalink)  
Old 07-01-04, 12:13
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
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.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On