forastero
15th September 2008, 02:00
hi,

i need to copy updated/new rows from some tables to an empty table. but i'm having some trouble here... checking all the rows in all tables everytime is not a good option :/

can you help me? :)

thanks.

EDIT: forgot to mention i can program on the empty table only.

mark_h
15th September 2008, 16:05
Well I am not a dba expert, but you could put a trigger on the original table. Then whenever a new record is inserted into the old table the trigger wakes up and copies the new row to the new table.

norwim
15th September 2008, 23:01
Hi there,

if the trigger solution is not applicable (tbase? :-) I see 2 other options depending on the actuality needed:
1) if the updates on the new table are not time critical, switch on audit for the source table and evaluate audit output every x minutes to insert into the new table according to audit information.
2) If you have to insert "instantly", you could write a session, that updates TWO (new) tables, the additional table records the last processed key of the table watched, so that your session only looks for new entries instead of reading all records. This session runs in an endless loop, sleeping the max amount of time you can accept according to the actuality required - this solution will not work if there is no way to identfy the "next higher" key in at least on index.

hth

Norbert

forastero
16th September 2008, 16:04
thank you for the answers.

it seems audit is the best option and i'll study how to use it properly.

if someone knows another solution, please feel free to post. :)

norwim
16th September 2008, 16:43
Hi forastero,

audit is indeed kewl, but keep in mind that audit files can NOT be accessed with usual select-statements from within a Baansession, as audit information is kept in ascii files at OS level. So your roadmap should be something like the following:
1) Change the database of the table to be monitored (usually you have two databases, which are identical ... but 1 is with and the other without audit :-) (Tools-Database Management-Assign Tables to Databases ttaad4111m000) --- Don't forget to convert to runtime! ---- If you want to check whether this has worked, have a look at $BSE/lib/tabledef6.1 - this file should be new and you should find your table there with a "Y" for audit switched on.
2) Now you must give at least one user the permission to read the audit informations:
(Tools-Audit Management-Assign Audit Security to Users) you have to be root to run this session!!
3) Now try to print audit information on the table in question - if this works, you made half the way :-)
4) Next thing is to build a job, which will periodically do the same thing, that is print audit information of the last period of time.
5) Make this job use an ascii-file instead of a printer. If this works, there is only one thing left: write a session that reads this file, identifies the new entries, reads them from the source table and inserts into the new table - call this session in the same job that generates audit info file as second session

good luck

Norbert