I'm assuming that you are retrieving dataset from webserver, and want to see it on a client. Otherwise, the question itself is meaningless.
Followings are what I'm doing now. Well, if I can find any better method, I'll use it.
Client side: sending request.
Dataset here is TBufDataSet in practice.
uses httpsend; // uses synapse. But you may use fphttpclient.
function Taq_r_6.DownloadQuery(SQLDef: TStrings; DataSet: TDataSet): Boolean;
var
QrStream: TStringStream;
ts: string;
begin
// SQLDef.SQLText = SQL text.
// Others are params.
ts := SQLDef.CommaText;
QrStream := TStringStream.Create(ts);
QrStream.Position := 0;
try
if HttpPostBinary(URL + 'GetQuery', QrStream) // httppostbinary is a function defined in httpsend
then begin
try
QrStream.Position := 0;
if Dataset <> nil
then (DataSet as TCustomBufDataSet).LoadFromStream(QrStream);
Result := True;
except
QrStream.Position := 0;
end;
end
else Result := False;
finally
QrStream.Free;
end;
end;
// An example of calling downloadquery.
function Taq_r_6.GetProjectList(uid: string; DataSet: TDataSet): Boolean;
var
tss: TStringList;
begin
tss := TStringList.Create;
tss.SkipLastLineBreak:= True;
try
tss.Append('SQLText=select * from Get_Project_List(:UID)'); // here, sqltext
tss.Append('uid=' + uppercase(uid)); // and parameters
Result := DownloadQuery (tss, DataSet);
finally
tss.Free;
end;
end;
Server side: running SQL and sending it as a response.
// following procedure is defined in a web-module
procedure TwmAQe.GetQuery2Request(Sender: TObject; ARequest: TRequest;
AResponse: TResponse; var Handled: Boolean);
var
memstr: TMemoryStream;
begin
memstr:= TMemoryStream.Create;
aq_fb6_e.DownLoadQuery(ARequest.Contentfields, memstr);
MemStr.Position := 0;
AResponse.ContentStream := memstr;
Handled := True;
end;
// and following procedure is stored in a separate datamodule, with database definition, etc.
function Taq_fb6_e.DownLoadQuery(SQLDef: TStrings; Data: TStream): boolean;
var
xqr: TSQLQuery;
AParam: TParam;
begin
xqr := TSQLQuery.Create(nil); // this is a TSQLQuery, which will connect to a Firebird database.
xqr.DataBase := fbAQ;
xqr.Transaction := trAQ;
try
xqr.SQL.Text := SQLDef.Values['SQLText'];
For AParam in xqr.Params do
AParam.AsString := SQLDef.VALUES[AParam.name];
try
xqr.Open;
xqr.SaveToStream(Data); // the opened dataset is saved to a stream,
xqr.Close;
Result := True;
except
Result := False;
end;
finally
trAQ.CommitRetaining;
xqr.Free;
end;
end;