Master/Detail , Firebird & Delphi7
Posted: 01.08.2006, 06:33
[font=Courier New]
Hi All,
I´m having a error message using master detail relationship and firebird.
When i apply updates i get an "foreign key violation'
The primary key value on master is generated in a before insert trigger on firebird server.
The problem is, when changes are applied on details, the primary key value on master is not updated with the value generated by the trigger.
I have a master table with 2 details.
I set the details properties like this :
On Save button of my application i put this code :
On master new record event, this code :
On detail new record event, this code :
Anyone can help me with some direction on this problem ?
Thanks in advanced,
Gustavo.
[/font]
Hi All,
I´m having a error message using master detail relationship and firebird.
When i apply updates i get an "foreign key violation'
The primary key value on master is generated in a before insert trigger on firebird server.
The problem is, when changes are applied on details, the primary key value on master is not updated with the value generated by the trigger.
I have a master table with 2 details.
I set the details properties like this :
Code: Select all
DataSource := dsCadCli; // master datasource
IndexfieldName := 'IDCAD'; // foreign key on detail table
MasterFields := 'ID'; // primary key on master table
MasterSource := dsCadCli; // same above
Code: Select all
qryCadCli.DisableControls;
try try
dbConnection.StartTransaction;
if( (qryCadCli.State = dsEdit) OR (qryCadCli.State = dsInsert) ) then qryCadCli.Post;
if( (qryCliEnd.State = dsEdit) OR (qryCliEnd.State = dsInsert) ) then qryCliEnd.Post;
if( (qryCliTel.State = dsEdit) OR (qryCliTel.State = dsInsert) ) then qryCliTel.Post;
qryCadCli.ApplyUpdates; // master table
qryCliEnd.ApplyUpdates; // detail table
qryCliTel.ApplyUpdates; // detail table
dbConnection.Commit;
Result := True;
except
dbConnection.Rollback;
raise;
end;
finally
qryCadCli.EnableControls;
end;
Code: Select all
procedure TdmDB.qryCadCliNewRecord(DataSet: TDataSet);
begin
DataSet.FieldByName('ID').AsString := '-1'; // this is the primary key
end; // TdmDB.qryCadCliNewRecord
Code: Select all
procedure TdmDB.qryCliEndNewRecord(DataSet: TDataSet);
begin
qryCliEnd.FieldByName('IDEND').AsString := '-1';
qryCliEnd.FieldByName('IDCAD').AsString := qryCadCli.FieldByName('ID').AsString; // this is the foreign key
end; // TdmDB.qryCliEndNewRecord
Thanks in advanced,
Gustavo.
[/font]