Master/Detail and cachedupdates
Posted: Thu 20 Dec 2007 00:36
I'm trying out sdac and I have a few questions for you:
I Have two tables:
Table Master
ID_Master : Int => AutoInc and primary key
Name : varchar
Table Detail
ID_Detail : Int => AutoInc and primary key
ID_Master : Int => fk to master table
Name : varchar
So, In my delphi application I have two tmsquery components:
Master:
SQL = select * from master
Insert = INSERT INTO master(name) VALUES (:name) SET :id_master = SCOPE_IDENTITY()
Detail
SQL = select * from detail
Insert = INSERT INTO detail (id_master, name) VALUES (:id_master, :name) SET :id_detail = SCOPE_IDENTITY()
My detail query has these propertys enabled: CachedUpdates, Options.ReturnParams.
My master query has only this property enabled: Options.ReturnParams.
I Wrote these events:
procedure TForm1.detailBeforeUpdateExecute(Sender: TCustomMSDataSet; StatementTypes: TStatementTypes; Params: TMSParams);
begin
if stInsert in StatementTypes then begin
Params.ParamByName('Id_Detail').ParamType := ptInputOutput;
Params.ParamByName('Id_Master').AsInteger := masterid_master.Value;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
master.Active := True;
detail.Active := True;
end;
procedure TForm1.masterAfterPost(DataSet: TDataSet);
begin
detail.ApplyUpdates;
end;
procedure TForm1.masterBeforeUpdateExecute(Sender: TCustomMSDataSet; StatementTypes: TStatementTypes; Params: TMSParams);
begin
if stInsert in StatementTypes then begin
Params.ParamByName('Id_Master').ParamType := ptInputOutput;
end;
end;
Everything works fine. But if I configure the detail query mastersource property (doing a master/detail) when I post the master query, nothing happens with the detail table and the records I inserted in the detail query are not posted to the sql server and the event BeforeUpdateExecute of the detail query is not triggered. What am I doing wrong?
I Have two tables:
Table Master
ID_Master : Int => AutoInc and primary key
Name : varchar
Table Detail
ID_Detail : Int => AutoInc and primary key
ID_Master : Int => fk to master table
Name : varchar
So, In my delphi application I have two tmsquery components:
Master:
SQL = select * from master
Insert = INSERT INTO master(name) VALUES (:name) SET :id_master = SCOPE_IDENTITY()
Detail
SQL = select * from detail
Insert = INSERT INTO detail (id_master, name) VALUES (:id_master, :name) SET :id_detail = SCOPE_IDENTITY()
My detail query has these propertys enabled: CachedUpdates, Options.ReturnParams.
My master query has only this property enabled: Options.ReturnParams.
I Wrote these events:
procedure TForm1.detailBeforeUpdateExecute(Sender: TCustomMSDataSet; StatementTypes: TStatementTypes; Params: TMSParams);
begin
if stInsert in StatementTypes then begin
Params.ParamByName('Id_Detail').ParamType := ptInputOutput;
Params.ParamByName('Id_Master').AsInteger := masterid_master.Value;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
master.Active := True;
detail.Active := True;
end;
procedure TForm1.masterAfterPost(DataSet: TDataSet);
begin
detail.ApplyUpdates;
end;
procedure TForm1.masterBeforeUpdateExecute(Sender: TCustomMSDataSet; StatementTypes: TStatementTypes; Params: TMSParams);
begin
if stInsert in StatementTypes then begin
Params.ParamByName('Id_Master').ParamType := ptInputOutput;
end;
end;
Everything works fine. But if I configure the detail query mastersource property (doing a master/detail) when I post the master query, nothing happens with the detail table and the records I inserted in the detail query are not posted to the sql server and the event BeforeUpdateExecute of the detail query is not triggered. What am I doing wrong?