How do I update multiple tables from using TMyQuery?

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
robbiem
Posts: 1
Joined: Thu 23 Aug 2007 06:31

How do I update multiple tables from using TMyQuery?

Post by robbiem » Thu 23 Aug 2007 06:51

This strikes me as a really obvious question:

I have a query:

select a.keyfield,a.field1,a.field2,b.anotherfield
from firsttable a left join secondtable b on b.keyfield=a.keyfield

I wish to use a data control to edit the result (let us say, Datagrid)
The TMyQuery component behaves very well as far as updating the fields in firsttable, but does not update secondtable (fair enough).

What I want to on Posting is a) work out if anotherfield has been modified, and b) generate a sql to update secondtable if so.

Which event should I trap on? How would I tell the dataset that I've handled the update for it?

OnUpdateRecord would seem obvious, but it doesn't seem to actually trigger.

BeforeUpdateRecord?

Antaeus
Posts: 2098
Joined: Tue 14 Feb 2006 10:14

Post by Antaeus » Thu 23 Aug 2007 11:44

You can the UpdatingTable property of your TMyQuery to specify for which of two tables in the query will be generated an update statement.
If you want to update both tables simultaneously, you should provide appropriate commands to SQLInsert, SQLUpdate, SQLDelete properties of you TMyQuery object.
If your handlers are complicated, you can attach TMyQuery, or TMyCommand components through the TMyUpdateSQL component to execute update commands. See the UpdateSQL demo included in MyDAC General demo for details. You can find MyDAC General demo in the MyDAC_InstDir\Demos\MyDACDemo directory.
MyDAC_InstDir is the MyDAC installation directory on your computer.

Post Reply