Problem with dbgrid which contains JOIN statement

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
gilbert3
Posts: 3
Joined: Wed 06 Sep 2006 08:36

Problem with dbgrid which contains JOIN statement

Post by gilbert3 » Fri 24 Nov 2006 09:37

I created 2 tables which contains some relation data. This two tables are joined with LEFT JOIN statement with Core Lab's "MyQuerry" component and DataSource , DbGrid included in Delphi 7. Fields are displaying correctly, but I'm wordering how to update second table, which contains ID relation with first table. I just wanted to update fields directly on dbGrid, but of course nothing happens in tables. Which property MyQuerry or DBGrid or maybe DataSource should I use to update fields in second table linked with LEFT JOIN.
Thank you very, very much.

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

Post by Antaeus » Fri 24 Nov 2006 09:55

Try to assign the name of the second table to the MyQuery.UpdatingTable property. You can find the information about this property in the MyDAC help.

gilbert3
Posts: 3
Joined: Wed 06 Sep 2006 08:36

Post by gilbert3 » Thu 30 Nov 2006 09:10

Antaeus wrote:Try to assign the name of the second table to the MyQuery.UpdatingTable property. You can find the information about this property in the MyDAC help.
Let me explain it - my code:

MyQuerry1.SQL:='select first_table.first_field, first_table.second_field, second_table.first_field from first_table left join second_table on first_table.id = second_table.first_table_id';


As we know how works "left join".: this SQL will display all records from first_table even second_table contains empty fields.

While UpdatingTable is selected od "second_table" MyDac displaying message 0 fields updated. It's happen because second_table is totally empty. It doesn't contain any data, just structure. I would like to fill second_table with data from first_table and from user with dbgrid.

I'll try to do something with master, detail. If somebody has some hints - thanks very much.

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

Post by Antaeus » Thu 30 Nov 2006 15:17

Solution with Master/Detail relationship should be better than a single query with the JOIN clause. Please see the MasterDetail demo of MyDAC. You can find this demo in %MyDAC%\Demos\MasterDetail directory.
%MyDac% is the MyDAC installation path on your computer.

Post Reply