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]