Page 1 of 1

Endless loop in fetching data of multiple queries

Posted: Mon 24 Aug 2009 13:10
by Olivier Olmer
We like to copy all results into a list of clientdatasets.

The following code will result in endless loop. But why?

example :
MSQuery.Sql.Text := 'Select * from customer Select * from order';

MSQuery.Execute;

if (MSQuery.Active) then begin
repeat
DatasetProvider := TDatasetProvider.Create(nil);
DatasetProvider.Dataset := MsQuery;
try
ClientDataset.Data := DatasetProvider.Data;
finally
DatasetProvider.Free;
end;
ClientDataset.Assign(MsQuery);
DatasetList.Add(ClientDataset);
until not MSQuery.OpenNext;
end


but if we modify it to it doesnot:
MSQuery.Execute;
if (MSQuery.Active) then begin
j := 0;
repeat
DecodeTime(now-lDTM, hh, mm, ss, mSec);

// Copy the data
VirtualTable:= TVirtualTable.Create(nil);
VirtualTable.Active := True;

VirtualTable.Assign(MsQuery);
DatasetList.Add(VirtualTable);
until not MSQuery.OpenNext;
end;

Why does it do open in the first example only the first query over and over?

With kind regards,

Olivier Olmer

Posted: Wed 26 Aug 2009 06:06
by Dimon
This is connected with TClientDataset functionality. The point is that TClientDataset on calling the Assign method executes the TDataSet.Open method itself.