master/detail and cachedupdates

Martin A

Member
Hello Marco,

I have an application (D5, Oracle 10.1.0.2.0, DOAD 4.0.7.1)
that acesses 4 tables which are related as follows:
1. articles: master table
2. remarks: detail table (exactly 1 record for each record of articles)
3. shipping: detail table (at least 1, possibly more records for each record of articles)
4. surcharge: detail table (possibly 1 or more records for each record of articles)

There's 1 Toracledataset for each of the tables all using the same OracleSession.
I have set the master property of the 3 detail datasets to the master dataset.

Now here's my questions:

In the Helpfiles (about TOracleSession.ApplyUpdates) there is stated that
in a master/detail relation each dataset must have its CachedUpdates property set to True
in order to have the updates in all detail datasets automatically applied along with the master dataset...
However, i don't want the user to be able to apply more than one master record at a time.
Also one of the detail datasets should be limited to have exactly 1 record for each master dataset.
How can i achieve this?

How do i have to invoke TOracleSession.ApplyUpdates?
like: OracleSession.ApplyUpdates([dsmaster,dsdetail1,dsdetail2,dsdetail3])
or does: OracleSession.ApplyUpdates([dsmaster]) do the trick?

Where should i best check for valid entries before applying/commiting changes?
I tried to put the code into the BeforePost event of the master dataset,
but i seem to get problems when there are multiple inserted/updated records pending
for one of the detail datasets that i want to check for duplicate entries
in fields with unique indexes...

I hope to be able to handle updates/deletes/cancels of all 4 datasets
with just 1 ToracleNavigator that is linked to the master dataset.
Can this work as a result of the master/detail relation of the datasets?
How can i get the Navigator to enable the Post/Cancel buttons if the User
did only change/add one of the detail datasets?

I read some posts in the google groups about cachedupdates and master/detail relations
and many of them state that there are problems with the built-in behaviour of Delphi (BDE-)components
(Tquery,TTable) in this situation and that one should rather handle the master/detail processing manually
when using cachedupdates...now i'm a bit confused...Would you recommend this for Toracledataset too
or is there a fundamental difference in the behaviour of the DOA components regarding cachedupdates and master/detail relations?
You see, on one hand i'm trying to figure out how to generally design a master/detail forms that handles cached updates
for Delphi client/server and i know well that it's not your job to teach me this in the first place,
but on the other hand, as most of the information you can find on the net deals with the standard BDE components,
i would be glad if you could spare some light on what issues might be similar with Toracledataset
or which ones of the known BDE - problems concerning this topic i might just forget working with DOAD.

Thanks in advance
Martin
 
However, i don't want the user to be able to apply more than one master record at a time.
Also one of the detail datasets should be limited to have exactly 1 record for each master dataset.
How can i achieve this?
In that case you cannot use the "standard" master/detail relation, because it will implicitly apply the detail datasets when a master is applies. Instead, you need to use unrelated datasets, explicitly control the master/detail synchronization where applicable, and apply the cached updates under your own control as well.
 
Thanks a lot for your answer,Marco...
just to be sure that i get you right:
basically there's nothing wrong with the master applying the details implicitly...
as long as i can guarantee that the user applies just one master at a time,
this is exactly what i want...
Does the problem appear when i want to restict one of the detail datasets to having
exactly 1 record for each master dataset?

Thanks again and have a nice weekend
Regards
Martin
 
It seems I misunderstood your requirements, and you should probably be able to use the standard master/detail relationship for this.

If you want to apply just one master record and multiple details, then it would seem that the master dataset does not use CachedUpdates. If CachedUpdates are disabled for the master, then each individual record is posted and committed. I think that the AfterPost event of the master dataset can be used to apply the cached updates of the details.

To restrict a detail dataset to exactly 1 record, you can probably use the OnNewRecord event to check if a 2nd record is added.
 
Thanks again Marco,
I just wonder...
quote from the Helpfile (Toraclesession.ApplyUpdates):

Does "Each" only apply to the details or does it include the master as well?
If the master record has cachedupdates disabled, and i use the AfterPost event to apply the detail updates, then is it possible to rollback the master record if an error occurs trying to apply the details?
Or could i have the master records cachedupdates enabled and manually prevent the User from moving to another (or inserting a new) master record without having saved or cancelled the updates to
the current one? Could this possibly be done checking the UpdatesPending properties of master and details in the BeforeAction event of the Toraclenavigator linked to the Master record and/or the BeforeScroll/BeforeInsert/BeforeQbe events of the master Dataset?
Regards
Martin
 
Does "Each" only apply to the details or does it include the master as well?
No, because you don't call ApplyUpdates for the master dataset. You essentially have seemingly unrelated detail datasets, all with cached updates.
If the master record has cachedupdates disabled, and i use the AfterPost event to apply the detail updates, then is it possible to rollback the master record if an error occurs trying to apply the details?
Only if for the Master dataset you have CommitOnPost disabled. In the after post event handler you can apply the cached updates for the detail datasets, and if all has gone well, commit the entire transaction. If something fails, you can rollback the entire transaction.
 
Hello Marco,
Thanks once again, really appreciate your help...
I'm out of office for a two weeks holiday right now
but i'll try this out immediately when i'm back...
have a nice weekend
Regards
Martin
 
Back
Top