Delete master-detail cached

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
betadevart
Posts: 18
Joined: Tue 20 Mar 2012 17:42

Delete master-detail cached

Post by betadevart » Wed 30 May 2012 21:56

I have a problem with deleting details from master-detail datasets.
The very simple case: want to delete all the details.
CachedUpdates=true for both datasets (master and detail).
the program works like that:
0.
master-details read ok, I see the correct data
1.
delete all records from details
delete master record
2.
I'm using separate UpdateTransaction
UpdateTransaction->StartTransaction()
detail->ApplyUpdates()
master->ApplyUpdates()
UpdateTransaction->Commit()
-----------------
No delete statements for the details! :-(
There is delete statement for master record.

I know there is an advice about LocalMasterDetail.
Does that mean that the very basic master-detail setup can not be used with cacched updates?
I thought that is the very basic usage of all. Do I miss something? How should I delete details in a cached way?
-------------
C++ Builder, Firebird, UniDac

betadevart
Posts: 18
Joined: Tue 20 Mar 2012 17:42

Re: Delete master-detail cached

Post by betadevart » Thu 31 May 2012 07:26

Maybe I have to forget master-detail magic inside UniDac and just use sql?
For instance: select * from orders where order.partner=:partner_id?

This way the different datasets work independently and correctly.
I guess I loose automatic transfer of generated ids. What else?

I can't image that many user work without cached updates (especially with gui),
so the classic master-detail dataset binding is just not usable!?
Would someone give a direction for real-life practice?

Thanks
Tamás

ZEuS
Devart Team
Posts: 240
Joined: Thu 05 Apr 2012 07:32

Re: Delete master-detail cached

Post by ZEuS » Fri 01 Jun 2012 10:55

Hello.

Such behavior is due to peculiarities of working with master-detail relationships when CachedUpdates is set to True.
When the CachedUpdates property of the detail dataset is set to True, all data changes in it are made locally, without applying them on the server until the ApplyUpdates method is called. But, when the current record in the master dataset is deleted, the detail dataset correspondingly updates its data from the server and all previously made changes are lost.
To get the behavior you have described, you should set the LocalMasterDetail property of the detail dataset to True.
By default, the LocalMasterDetail property is set to False in order to reduce network traffic to the server and increase performance.
You can find more information about master-detail relationships in the "Working with Master/Detail Relationships" article of the UniDAC documentation.

betadevart
Posts: 18
Joined: Tue 20 Mar 2012 17:42

Re: Delete master-detail cached

Post by betadevart » Fri 01 Jun 2012 12:17

Thanks for answering

My understanding of LocalMasterDetail was that when I set true all the details comes over the wire and only filtered by the client detail UniQuery, not the sql sent to server.
Is it false assumption? When you mention performance reasons I think about that.

In my example I do detail->ApplyUpdates() *first*. No master should do anything - no lost detail changes - if CachedUpdates=true. Isn't it true?

In the meantime I'm trying skip internal master-details, and use simple "where foriegn_key=master_id" for that myself. But it would be certainly usefull to understand more.

betadevart
Posts: 18
Joined: Tue 20 Mar 2012 17:42

Re: Delete master-detail cached

Post by betadevart » Fri 01 Jun 2012 12:32

...more on that

I've tried the other way you suggested. It seems I was right. Using internal master-detail and turning LocalMasterDetail=true makes the detail select statement to read the whole table.
It is just unacceptable. We all call it master-detail! The two orignal questions are just not in the same class.
1. Master-detail means using/transferring only the necessary rows.
2. CacheUpdates means applying updates after all complex client manipulation only.

I see no solution, since not any of the two can be given up in the choice of other.
Please show me the light!

Regards,
Tamás

Post Reply