Cached Updates

jlcox

Member³
I am inserting new master/detail information from a user form. The master and detail queries are both set to use cached updates. Since the detail records must have a valid reference to the master's primary key, I set that value to 0 when initializing the form. When posting the information, I'm using this bit of code:

try
dm.OracleSession1.ApplyUpdates([dm.qryRequest], False);
except
dm.OracleSession1.Rollback;
raise;
end;
dm.OracleSession1.CommitUpdates([dm.qryRequest]);

The real primary key of the qryRequest (the master table) is generated by a trigger, so until the master is posted, the details can't know the real value. I'm handling this part through the OnApplyRecord event handler for the detail query, ie.,

if Action = 'I' then
qryReqItems['REQUEST_ID'] := qryRequest['REQUEST_ID'];
Applied := False;

So far this seems to work fine, except for one small problem. If I create a second request, the original information is still displayed, i.e., CommitUpdates doesn't clear the cache.

First question: Is my approach to the basic problem (setting bogus primary key, then generating a new one and updating the details as they are applied) a safe or recommended methodology?

Second: What have a probably failed to set properly to make the local cache evaporate?
 
I don't think this is currently possible. The details need to know the actual value of the master dataset. If you are generating the primary key of the master table through a sequence, you might consider using the SequenceField of the master dataset. Make sure that you set the SequenceField.ApplyMoment property to amOnNewRecord in this case.

------------------
Marco Kalter
Allround Automations
 
OK, I switched over to using the method you suggested, also disabling the sequence trigger on the server. The data posts properly, but I still have the problem with the cache not clearing when the updates are committed. The datasets are closed and the form is destroyed after the information is posted, yet when I create a new form and re-open the queries, I still see the information that I entered earlier. Shouldn't applying and committing the cached queries clear the information?
 
CommitUpdates clears the change log, there is no question about that. If an exception occurs in your example, the change log will still contain the original cached updates though. You can call CancelUpdates in this situation.

------------------
Marco Kalter
Allround Automations
 
Back
Top