I am switching from SQL to MYSQL and could use some help retrieving the value of the auto increment index of the Master Table. I'm sure my way of doing so even when using SQL may have been wrong but it worked so I assumed what I was doing was OK. Anyway, what I had been doing was to Post, then do a
LastID := DM.Markers.Dataset.FieldByName('Marker_ID').AsInteger;
and use LastID in my Foreign Key field in the Detail Table Record. That has always worked perfectly.
Now that I'm trying to switch over to MYSQL I get 0 back for LastID when doing so. I know that in MYSQL there is a function LAST_INSERT_ID(); that can be executed but I'm not sure how or where to use that. Can someone point me in the right direction please? Thanks!
Master Detail Tables
-
DemetrionQ
- Devart Team
- Posts: 271
- Joined: Wed 23 Jan 2013 11:21
Re: Master Detail Tables
Hello.
1) MyDAC automatically fills in auto-incremental fields on calling the TCustomDADataSet.Post method if the TCustomDADataSet.CachedUpdates proeprty is set to False. If TCustomDADataSet.CachedUpdates is set to True, auto-incremental fields are filled in on calling the TCustomDADataSet.ApplyUpdates method.
2) When master-detail relationship is configured correctly, you don't need to manually set the foreign key field on inserting a new record to the detail table - MyDAC does this automatically. The detailed information about master-detail relationship can be found at http://www.devart.com/mydac/docs/work_md.htm
To solve the problem, make sure that the CachedUpdates property is set to False for the master table. Also make sure you have configured master-detail relationship correctly.
1) MyDAC automatically fills in auto-incremental fields on calling the TCustomDADataSet.Post method if the TCustomDADataSet.CachedUpdates proeprty is set to False. If TCustomDADataSet.CachedUpdates is set to True, auto-incremental fields are filled in on calling the TCustomDADataSet.ApplyUpdates method.
2) When master-detail relationship is configured correctly, you don't need to manually set the foreign key field on inserting a new record to the detail table - MyDAC does this automatically. The detailed information about master-detail relationship can be found at http://www.devart.com/mydac/docs/work_md.htm
To solve the problem, make sure that the CachedUpdates property is set to False for the master table. Also make sure you have configured master-detail relationship correctly.
Re: Master Detail Tables
I had everything set except for the fact that my detail field names I had as Marker_ID_FK and the master was Marker_ID. I modified the detail field to Marker_ID and updated my Select Statement on the detail and all is working. Thanks!
-
DemetrionQ
- Devart Team
- Posts: 271
- Joined: Wed 23 Jan 2013 11:21
Re: Master Detail Tables
If any other questions come up, please contact us.