Master Detail Cache Update

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
doublehelix
Posts: 9
Joined: Mon 28 Dec 2009 23:42

Master Detail Cache Update

Post by doublehelix » Mon 28 Dec 2009 23:58

I've got a cached master/detail table and everything works great on the initial entry of an item. However after posting, applying, and committing changes the detail table does not have the record key of the master table. I've set it up according to instructions given in the help file, and according to it, this relationship should be created automatically.

Does it not happen with a cached master/detail entry? I'm using a cached entry so that users can cancel out of the data entry form and no updates are made.

Is there something additional I should be doing because I am caching?

I've noticed in the help file there is this statement under cachedupdates property:
NOTE: When establishing master/detail relationship the CachedUpdates property of detail dataset works properly only when TCustomDADataSet.Options is set to True.

Options has more than one property, so how can it be set to true. Through some additional research I assume that it means the LocalMasterDetail option. Is there anything else that needs to be set? Because, as I said, the master detail relationship works initially, but the values for the link are not being posted to the detail database.

I've also tried to forcibly post the values to the detail record link by setting them manually in the Update record event. But with a trace, the values show, but they are still not being posted.

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Tue 29 Dec 2009 15:14

When establishing master-detail relationship the CachedUpdates property of detail dataset works properly only when TCustomDADataSet.Options.LocalMasterDetail is set to True. Therefore to solve the problem you should set the LocalMasterDetail option to True.
You can find more detailed information about this in the MyDAC help.

doublehelix
Posts: 9
Joined: Mon 28 Dec 2009 23:42

Done that

Post by doublehelix » Tue 29 Dec 2009 16:09

Dimon wrote:When establishing master-detail relationship the CachedUpdates property of detail dataset works properly only when TCustomDADataSet.Options.LocalMasterDetail is set to True. Therefore to solve the problem you should set the LocalMasterDetail option to True.
You can find more detailed information about this in the MyDAC help.

I've done this, and yes, when this option is not set the caching will not work at all and the app errors out.

I'm using an auto-incrementing field in a customer list and linking it in a master-detail with an address list. As I said on initial entry everything appears to work properly. I'm using a tabbed entry for the addresses that will be associated with the customer record. I can move among the tabs when first entering data and the different addresses show in the appropriate tabs. However after committing the transactions the detail record link field does not contain an associated record number of the master table, its null.

doublehelix
Posts: 9
Joined: Mon 28 Dec 2009 23:42

Re: Done that

Post by doublehelix » Tue 29 Dec 2009 19:04

doublehelix wrote:
Dimon wrote:When establishing master-detail relationship the CachedUpdates property of detail dataset works properly only when TCustomDADataSet.Options.LocalMasterDetail is set to True. Therefore to solve the problem you should set the LocalMasterDetail option to True.
You can find more detailed information about this in the MyDAC help.

I've done this, and yes, when this option is not set the caching will not work at all and the app errors out.

I'm using an auto-incrementing field in a customer list and linking it in a master-detail with an address list. As I said on initial entry everything appears to work properly. I'm using a tabbed entry for the addresses that will be associated with the customer record. I can move among the tabs when first entering data and the different addresses show in the appropriate tabs. However after committing the transactions the detail record link field does not contain an associated record number of the master table, its null.
Looks like the only way around this was to finally dump the caching altogether and use the transaction rollback feature of the MyConnection. It ment I had to create a MyConnection for every form because the program is MDI and multiple customer entry forms can be opened at once.

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Wed 30 Dec 2009 07:47

Please send me a complete small sample to dmitryg*devart*com to demonstrate the problem, including a script to create and fill table.

Justmade
Posts: 108
Joined: Sat 16 Aug 2008 03:51

Post by Justmade » Wed 30 Dec 2009 14:10

I also have similar experience that when cache update + localmasterdetail, The linked key is automatically set on memory but not write to database when applyupdate. I had subclass the TMyQuery and set the key values in my own code is DoAfterInsert and then it write to database.

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Mon 04 Jan 2010 08:33

The problem is that when you are using autoincrement values that are used as link values for detail table in master table, there is no possibility to know new autoincremented value until executing ApplyUpdate.
To solve the problem you can use the DoAfterInsert event handler, or you should insert or update records in datail table after posting changes in master table using ApplyUpdate.

Post Reply