Progress event when fetchning data

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
zvasku
Posts: 77
Joined: Tue 19 Sep 2006 12:04

Progress event when fetchning data

Post by zvasku » Fri 06 Jan 2012 17:31

Hello,

is it possible to add event for progress when fetchnig data from db server to TUniQuery (etc.).

When fetching large amount of data, App.ProcessMessages to refresh app should be usefull.

Thanks
Zdenek

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Post by AlexP » Mon 09 Jan 2012 08:46

Hello,

For displaying the process of fetching data from the server you can use the AfterFetch event.
For this you should set the FetchAll option to false and set necessary value in the FetchRows property, for example:

Code: Select all

var
  FCounter: integer;

procedure TForm1.UniQuery1AfterFetch(DataSet: TCustomDADataSet);
begin
  if UniQuery1.RecordCount > 0 then
    ProgressBar1.Position := Round(100*FCounter/UniQuery1.RecordCount);
  FCounter := FCounter + UniQuery1.FetchRows;
  Application.ProcessMessages;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  FCounter:= 0;
  UniQuery1.SpecificOptions.Values['FetchAll'] := 'false';
  UniQuery1.FetchRows := 25;
  UniQuery1.Options.QueryRecCount := true;
  UniQuery1.Open;
  UniQuery1.Last;
end;

zvasku
Posts: 77
Joined: Tue 19 Sep 2006 12:04

Post by zvasku » Mon 09 Jan 2012 10:50

I will test it.

Thanks
Zdenek

zvasku
Posts: 77
Joined: Tue 19 Sep 2006 12:04

Post by zvasku » Mon 09 Jan 2012 14:54

Work well, but I need it with TClientDataset-TDatasetProvider where RecourdCount returns 0 (table is not Active). It is ok for this situation.

Is it valid to use FRecordCount in this case?

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Post by AlexP » Wed 11 Jan 2012 12:23

Hello,

For the mapping of the data-getting process in ClientDataSet you should set the ClientDataSet.PacketRecord property equal to UniQuery.FetchRows and use the ClientDataSet.GetData event for the mapping of the data-getting process

Code: Select all

procedure TForm1.Button1Click(Sender: TObject);
begin
ClientDataSet1.PacketRecords := 25;
ClientDataSet1.Open;
  while not ClientDataSet1.eof do
    ClientDataSet1.next;
end;

procedure TForm1.DataSetProvider1GetData(Sender: TObject;
  DataSet: TCustomClientDataSet);
begin
if ClientDataSet1.Active then ShowMessage(IntToStr(ClientDataSet1.RecordCount));
end;

zvasku
Posts: 77
Joined: Tue 19 Sep 2006 12:04

Post by zvasku » Thu 12 Jan 2012 09:14

It is another approach. I need to load complete dataset when opening. I only need progressbar or processmessages during one single open:

ShowPorogress;
ClientDataset.Open;
HideProgress;

...

ClientDataset.AddIndex .... etc.

...

Showmodal;

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Post by AlexP » Thu 12 Jan 2012 11:15

Hello,

ClientDataset does not call any events when retrieving data, that is why you can not visualize the data obtaining process when simply opening ClientDataset (TClientDataset.open)

zvasku
Posts: 77
Joined: Tue 19 Sep 2006 12:04

Post by zvasku » Thu 12 Jan 2012 11:42

Yes, but I can use connected TUniQUery to do that. It works good with AfterFetch, also QueryRecCount work as expected.

I'm olny use FRecordCount instead of RecordCount.

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Post by AlexP » Thu 12 Jan 2012 15:27

Hello,

Please, specify the component, whose property FRecordCount you use.

zvasku
Posts: 77
Joined: Tue 19 Sep 2006 12:04

Post by zvasku » Thu 12 Jan 2012 16:02

TUniQuery

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Post by AlexP » Fri 13 Jan 2012 10:01

Hello,

The FRecordCount field is a protected field of the class, and UniQuery retrieves the value of this field with the help of the RecordCount event. There are special methods implemented for retrieving the number of records depending on the UniQuery. settings. So, if you have even got access to the FRecordCount event, then, most probably, you will retrieve the wrong number of records.

Post Reply