How could i access the datamodule from out RAP. Goal, i want to edit one of the datasets queries to enter the famous top x clause after the autosearchfields where updated.
From the Help i think i should update the SQL with the TdaSQLBuilder class, but there i can't access the sql directly, and i don't want to change something to fields, criteria, .... But when accessing the strings directly, even over a second stringlist, no changes, even a clear of the SQLText field doesn't result in any changes.
Any suggestion ??
procedure TSdwRapSql_Add_TopXFunction.ExecuteFunction(aParams: TraParamList); var ..... begin GetParamValue(0, lReport); GetParamValue(1, ldSetName); GetParamValue(2, TopX); aSQL := nil; lDataModule := daGetDataModule(lReport.MainReport); if (lDataModule <> nil) then begin liIndex := 0; while (liIndex < lDatamodule.DataViewCount) and (aSQL = nil) do begin lDataView := lDataModule.DataViews[liIndex]; if (lDataView <> nil) then if lDataView.UserName = ldSetName then begin MyList := TStringList.Create; aSQL := TdaADOQueryDataView(lDataView).SQL; MyList.AddStrings(aSql.SQLText); MyList.Strings[0] := MyList.Strings[0] + ' TOP ' + IntToStr(TopX); aSql.SQLText.Clear; aSql.SQLText.AddStrings(MyList); MyList.Free; end; Inc(liIndex); end; end; end;
I had never tried using TdaSQLBuilder to modify the sql text, so I gave it a try and it appeared to work.
I tried a Delphi example and then a RAP example - see both below. I used the RB 9.02 and the BeforeOpenDataPipelines event.
1. Delphi code
procedure TForm1.ppReport1BeforeOpenDataPipelines(Sender: TObject); var lSQLBuilder: TdaSQLBuilder; begin lSQLBuilder := TdaSQLBuilder.Create(ppReport1.DataPipeline);
lSQLBuilder.SQL.EditSQLAsText := True; lSQLBuilder.SQL.SQLText.Text := 'Select * from Customer';
lSQLBuilder.ApplyUpdates;
lSQLBuilder.Free;
end;
2. RAP code
var lSQLBuilder: TdaSQLBuilder; begin lSQLBuilder := TdaSQLBuilder.Create(Customer); lSQLBuilder.SQL.EditSQLAsText := True; lSQLBuilder.SQL.SQLText.Text := 'Select * from Customer';
Nard, until now i did al this in a Passthru. Now i would like to test it in Rap. But this lSQLBuilder := TdaSQLBuilder.Create(Customer); , what is Customer. It is not a DADE query, because i can't reference them ...
The example passes the DataPipeline object to the TdaSQLBuilder constructor.
lSQLBuilder := TdaSQLBuilder.Create(Customer
All of the components in ReportBuilder have a UserName property that is used by RAP to resolve object references.
1. A DADE QueryDataView internally manages a datapipeline. From the SQL tab of the Query Designer you can assign a name to your query. This value is assigned to the DataPipeline.UserName
2. The RAP Code Toolbox displays the UserName's for the available DataPipelines.
3. Pass the DataPipeline.UserName to the TdaSQLBuilder constructor
Best regards,
Nard Moseley Digital Metaphors www.digital-metaphors.com
Comments
I would try to get this working using Delphi code and then code a pass-thru
function that can be called from RAP.
--
Nard Moseley
Digital Metaphors Corporation
http://www.digital-metaphors.com
Best regards,
Nard Moseley
Digital Metaphors
www.digital-metaphors.com
but there i can't access the sql directly, and i don't want to change
something to fields, criteria, ....
But when accessing the strings directly, even over a second stringlist, no
changes, even a clear of the SQLText field doesn't result in any changes.
Any suggestion ??
procedure TSdwRapSql_Add_TopXFunction.ExecuteFunction(aParams:
TraParamList);
var
.....
begin
GetParamValue(0, lReport);
GetParamValue(1, ldSetName);
GetParamValue(2, TopX);
aSQL := nil;
lDataModule := daGetDataModule(lReport.MainReport);
if (lDataModule <> nil) then
begin
liIndex := 0;
while (liIndex < lDatamodule.DataViewCount) and (aSQL = nil) do
begin
lDataView := lDataModule.DataViews[liIndex];
if (lDataView <> nil) then
if lDataView.UserName = ldSetName then
begin
MyList := TStringList.Create;
aSQL := TdaADOQueryDataView(lDataView).SQL;
MyList.AddStrings(aSql.SQLText);
MyList.Strings[0] := MyList.Strings[0] + ' TOP ' + IntToStr(TopX);
aSql.SQLText.Clear;
aSql.SQLText.AddStrings(MyList);
MyList.Free;
end;
Inc(liIndex);
end;
end;
end;
I had never tried using TdaSQLBuilder to modify the sql text, so I gave it a
try and it appeared to work.
I tried a Delphi example and then a RAP example - see both below. I used the
RB 9.02 and the BeforeOpenDataPipelines event.
1. Delphi code
procedure TForm1.ppReport1BeforeOpenDataPipelines(Sender: TObject);
var
lSQLBuilder: TdaSQLBuilder;
begin
lSQLBuilder := TdaSQLBuilder.Create(ppReport1.DataPipeline);
lSQLBuilder.SQL.EditSQLAsText := True;
lSQLBuilder.SQL.SQLText.Text := 'Select * from Customer';
lSQLBuilder.ApplyUpdates;
lSQLBuilder.Free;
end;
2. RAP code
var
lSQLBuilder: TdaSQLBuilder;
begin
lSQLBuilder := TdaSQLBuilder.Create(Customer);
lSQLBuilder.SQL.EditSQLAsText := True;
lSQLBuilder.SQL.SQLText.Text := 'Select * from Customer';
lSQLBuilder.Free;
end;
--
Nard Moseley
Digital Metaphors Corporation
http://www.digital-metaphors.com
Best regards,
Nard Moseley
Digital Metaphors
www.digital-metaphors.com
Now i would like to test it in Rap.
But this lSQLBuilder := TdaSQLBuilder.Create(Customer); , what is Customer.
It is not a DADE query, because i can't reference them ...
Any suggestion .....
The example passes the DataPipeline object to the TdaSQLBuilder constructor.
lSQLBuilder := TdaSQLBuilder.Create(Customer
All of the components in ReportBuilder have a UserName property that is used
by RAP to resolve object references.
1. A DADE QueryDataView internally manages a datapipeline. From the SQL tab
of the Query Designer you can assign a name to your query. This value is
assigned to the DataPipeline.UserName
2. The RAP Code Toolbox displays the UserName's for the available
DataPipelines.
3. Pass the DataPipeline.UserName to the TdaSQLBuilder constructor
Best regards,
Nard Moseley
Digital Metaphors
www.digital-metaphors.com