Endless loop in fetching data of multiple queries

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Olivier Olmer
Posts: 8
Joined: Wed 09 Mar 2005 12:11

Endless loop in fetching data of multiple queries

Post by Olivier Olmer » 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

Dimon
Devart Team
Posts: 2888
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Wed 26 Aug 2009 06:06

This is connected with TClientDataset functionality. The point is that TClientDataset on calling the Assign method executes the TDataSet.Open method itself.

Post Reply