MyDAC & C++Builder
MyDAC & C++Builder
Hi !!
I have 2 Tables : SALE & DSALE Master / Detail in myisam format
the probleme is that i can't delete the detail rows when i delete the master row even when i use the onbeforepost event for the master Query
(I used 2 TMyQuery components)
so could you help me resolve this ???
thanks for all
I have 2 Tables : SALE & DSALE Master / Detail in myisam format
the probleme is that i can't delete the detail rows when i delete the master row even when i use the onbeforepost event for the master Query
(I used 2 TMyQuery components)
so could you help me resolve this ???
thanks for all
Re: MyDAC & C++Builder
Maybe OnBeforeDelete eventsaidus wrote:onbeforepost event
on master query you should do something similar to this,
When you try to delete master field, it deletes details (Of course you have to set correct query).
Code: Select all
procedure TFrmPacients.DBQpacfitBeforeDelete(DataSet: TDataSet);
begin
Connection.ExecSQL('delete from detailtable where field = '+BQpacfitcodigo_paciente.AsString,[]);
end;
More easy way for delete details:
or in designtime
MyQuery editor :: Udate SQLs :: Delete
Note: In this case MyQueryMaster->Options->StrictUpdate must be false
Code: Select all
MyQueryMaster->SQLDelete = "DELETE master, detail FROM master, detail
WHERE master.id = detail.master_id and master.id = :Old_id";
MyQuery editor :: Udate SQLs :: Delete
Code: Select all
DELETE master, detail FROM master, detail
WHERE master.id = detail.master_id and master.id = :Old_id
Hello !!!
I have a memory access error msg !!
the real problem is :
when deleting master record i use this code in OnBeforeDelete event
((( note : MasterTable = TMyQuery , DetailTable = TMyTable )))
but in OnAfterDelete and OnAfterPost detail table i have to calculate some value to store in Master table like this
thnks for help
I have a memory access error msg !!
the real problem is :
when deleting master record i use this code in OnBeforeDelete event
Code: Select all
TableDetail->First();
while(!TableDetail->Eof)
{
TableDetail->Delete();
}
but in OnAfterDelete and OnAfterPost detail table i have to calculate some value to store in Master table like this
Code: Select all
Extended tot = 0;
if(MasterTable->State!=dsEdit)
MasterTable->Edit();
DetailTable->First();
while(!DetailTable->Eof)
{
tot+=DetailTableQT->Value;
DetailTable->Next();
}
MasterTableQT->Value = tot;
MasterTable->Post();
You can use (for MySQL 4.1+):
instead of
and http://www.crlab.com/forums/viewtopic.php?t=2139#7116
instead of
It must increase perfomance of your application. Sorry for nag
Code: Select all
SQL: update master set qt = (select sum(detail.qt) from detail where detail.master_id=master.id ) where id= :MasterId
MasterTable->RefreshRecord();
Code: Select all
Extended tot = 0;
if(MasterTable->State!=dsEdit)
MasterTable->Edit();
DetailTable->First();
while(!DetailTable->Eof)
{
tot+=DetailTableQT->Value;
DetailTable->Next();
}
MasterTableQT->Value = tot;
MasterTable->Post();
instead of
Code: Select all
TableDetail->First();
while(!TableDetail->Eof)
{
TableDetail->Delete();
}