Migration from TSQLDataSet to TUniQuery I have problem with .First

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
ecosoft.it
Posts: 12
Joined: Thu 01 Dec 2011 14:36
Contact:

Migration from TSQLDataSet to TUniQuery I have problem with .First

Post by ecosoft.it » Thu 03 Jan 2013 14:08

I began the porting of my Application from DBExpress to UniDac.
If use UniQuery.unidirectional=true for two loop I have a strange problem. The first loop it work but the second loop count 10 - 11 record and exit.
If read ID before loop is non equal in the two times.
If I use identical code with TSQLDataSet don't have problem and loop count is identical on first and second loop.

Code: Select all

var
  qr: TUniQuery; //TSQLDataSet;
  c: integer;
begin
  qr := TUniQuery.Create(nil); // := TSQLDataSet.Create(nil);
  qr.UniDirectional := true;  // Remove in DBExpress
  qr.Connection := UniConnection1; // qr.SQLConnection := SQLConnection1;
  qr.SQL.Text := 'select * from CFANAGRA';
  qr.Open;
  c := 0;
  Memo1.Lines.Add('First ID ' + qr.FieldByName('ID').AsString);
  while not qr.Eof do
  begin
    Inc(c);
    qr.Next;
  end;
  Memo1.Lines.Add('First ' + IntToStr(c));

  qr.First; // <----- Return on top but not work with UniDac
  c := 0;
  Memo1.Lines.Add('Second ID ' + qr.FieldByName('ID').AsString);
  while not qr.Eof do
  begin
    Inc(c);
    qr.Next;
  end;
  Memo1.Lines.Add('Second ' + IntToStr(c));
end;
Result TUniQuery:
First ID 1
First 18285
Second ID 24647
Second 10

Result TSQLDataSet:
First ID 1
First 18285
Second ID 1
Second 18285

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

Re: Migration from TSQLDataSet to TUniQuery I have problem with .First

Post by AlexP » Tue 08 Jan 2013 12:39

Hello,

The UniQuery behaviour is different from the DBExpress DataSet behaviour when the UniDirectional mode is enabled. In UniDAC, navigation through dataset in this mode is available within the last fetched record set (the number of records is specified in the FetchRows property). This mode provides for memory saving, and for this we store only the last fetched rows, therefore the First method will move to the beginning of the last block.
To move to the first record, you should reopen DataSet.

Post Reply