Endless loop in fetching data of multiple queries
Posted: Mon 24 Aug 2009 13:10
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
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