Forcibly fetch remainig rows for each dataset?

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Ludek
Posts: 296
Joined: Thu 12 Oct 2006 09:34

Forcibly fetch remainig rows for each dataset?

Post by Ludek » Thu 18 Jan 2007 10:43

Hi, I'm having trouble with TMSConnection and FetchAll=false. I already know, that there's problem with starting transaction with unfetched rows, so I simply want do fetch all already unfetched datasets. Ho can I do it? Can't find any such method, thus I'm using following now:

Code: Select all

  for i := 0 to connection.DataSetCount - 1 do begin
    if connection.DataSets[i] is TCustomMSDataset then begin
      ds := connection.DataSets[i] as TCustomMSDataset;
      if not ds.FetchAll then begin
        ds.FetchAll := true;
        ds.FetchAll := false;
      end;
    end;
  end;
I simple HAVE TO start the transaction, what is the best solution? My solution works, but I don't like it at all :x

Jackson
Posts: 512
Joined: Thu 26 Jan 2006 10:06

Post by Jackson » Thu 18 Jan 2007 14:43

Try to use the following construction:

Code: Select all

 var
  Bookmark: TBookmark;
 begin
  ...
  DataSet.DisableControls;
  try
    Bookmark := DataSet.GetBookmark;
    DataSet.Last;
    DataSet.GotoBookmark(Bookmark);
  finally
    DataSet.EnableControls;
  end;
 ..
instead of:

Code: Select all

  ...
  DataSet.FetchAll := True;
  DataSet.FetchAll := False;
  ...

Ludek
Posts: 296
Joined: Thu 12 Oct 2006 09:34

Post by Ludek » Thu 18 Jan 2007 15:36

Ok, it seems to be also good enough. Other question: Would it be enough, if I test "not ds.fetched" instead of "not ds.fetchall"? So that it runs fastest possible... and what about datasets with fetchall = false and no records at all? I had trouble one time, when I tried to gotobookmark to a bookmark from empty dataset (some access violation :? )
Next question - do i need a freebookmark or is it superfluous?
In the SDAC code, there's a call to FetchAll of an component, if the fetchall is being set to true. I would like to call it myself, but the component is no public property... Could I try to call it myself or is it somehow dangerous???

Jackson
Posts: 512
Joined: Thu 26 Jan 2006 10:06

Post by Jackson » Fri 19 Jan 2007 12:44

> Would it be enough, if I test "not ds.fetched" instead of "not ds.fetchall"?
Yes, it is a good idea to call the TCustomMSDataSet.Fetched function to check if DataSet is already fetched.
> and what about datasets with fetchall = false and no records at all?
As for empty DataSet and the TDataSet.GotoBookmark method, everything should be alright, but if you have any troubles, please let us know.
> do i need a freebookmark or is it superfluous?
Yes, you have to сall TDataSet.FreeBookmark to free an existing bookmark.
> ... Could I try to call it myself or is it somehow dangerous???
We do not recommend you to do so.

Ludek
Posts: 296
Joined: Thu 12 Oct 2006 09:34

Post by Ludek » Fri 19 Jan 2007 16:10

Could you please add such method, that fetches all not yet fetched data, to the tcustommsdataset class or some ancestor class? I think, many people using SDAC and fetchall = false would appreciate it. Or even a method for the connection, that simple fetches all data from all open datasets. Or do you have any better solution, how could i start a transaction, if some unfetched records are still pending?? Thanks very much for the answers.

Jackson
Posts: 512
Joined: Thu 26 Jan 2006 10:06

Post by Jackson » Mon 22 Jan 2007 14:02

We will add such functionality in the next SDAC version.

Ludek
Posts: 296
Joined: Thu 12 Oct 2006 09:34

Post by Ludek » Mon 22 Jan 2007 14:13

Thanks a lot!

Ludek
Posts: 296
Joined: Thu 12 Oct 2006 09:34

Post by Ludek » Mon 23 Jul 2007 19:14

I am looking now for this added function in current SDAC3, but I can't find it. what's its name? thanks!

Ludek
Posts: 296
Joined: Thu 12 Oct 2006 09:34

Re: Forcibly fetch remainig rows for each dataset?

Post by Ludek » Mon 23 Jul 2007 19:51

or, please, tell me, if I can do following:

instead of

Code: Select all

        ds.FetchAll := true;
        ds.FetchAll := false;
this code

Code: Select all

        TMSAccessUtils.FIRecordSet(ds).FetchAll; 
        ds.Resync([]); 
the first code closes in current sdac3 version the dataset :(

Antaeus
Posts: 2098
Joined: Tue 14 Feb 2006 10:14

Post by Antaeus » Tue 24 Jul 2007 08:14

The functionality discussed above has not been implemented yet. It will not be implemented in SDAC 3, as SDAC 3 is no more developed.
You should use the solution posted above.
Jackson wrote:

Code: Select all

 var
  Bookmark: TBookmark;
 begin
  ...
  DataSet.DisableControls;
  try
    Bookmark := DataSet.GetBookmark;
    DataSet.Last;
    DataSet.GotoBookmark(Bookmark);
  finally
    DataSet.EnableControls;
  end;
 ..

Ludek
Posts: 296
Joined: Thu 12 Oct 2006 09:34

Post by Ludek » Tue 24 Jul 2007 12:51

This solution makes me not happy, because it often changes the position in grid - the selected record remains the same, but after gotobookmark it is the first visible record in grid, or the last, simply the users do not see the same records as before :(
My solution seems to work fine, is something wrong with it?
Will this function be available in the next SDAC4?
When comes the next release of SDAC4? I can't use the current SDAC4 because of those sloooooooooooooow calculated fields :cry:
Thanks much for answer!

Antaeus
Posts: 2098
Joined: Tue 14 Feb 2006 10:14

Post by Antaeus » Wed 25 Jul 2007 07:38

Ludek wrote:My solution seems to work fine, is something wrong with it?
This solution should work, but it does not save the record position in the grid, so it works like the solution we suggested. Moreover, we do not grantee that internal SDAC methods in future releases will be compatible with the current ones. So your solution may stop working in the future.
Ludek wrote:Will this function be available in the next SDAC4?
We will add functionality when dataset open in FetchAll=False mode completes fetching when setting FetchAll to True in the next version of SDAC. It will be SDAC 4.20. SDAC 4.20 will be available in beta very soon.
Ludek wrote:When comes the next release of SDAC4?
The next build of SDAC that solves the problem with lookup fields will be available during one week.

Ludek
Posts: 296
Joined: Thu 12 Oct 2006 09:34

Post by Ludek » Wed 25 Jul 2007 08:07

Antaeus wrote: This solution should work, but it does not save the record position in the grid, so it works like the solution we suggested.
Well, I tried it (I mean my last solution), and it never changed the top visible row in the grid :) It only changes the size and the position of the scrollbar thumb - and that is really no problem.
Antaeus wrote: Moreover, we do not grantee that internal SDAC methods in future releases will be compatible with the current ones. So your solution may stop working in the future.
I understand this. I need it only for the versions without the promised functionality - for versions < 4.20, especially for SDAC3. And, as you said, version 3 is not developed any more, so I don't see any danger. 8)
Antaeus wrote: SDAC 4.20 will be available in beta very soon.
I just can't wait for it :twisted:

Thanks a lot!

Post Reply