TZCachedResultSet - Read-only unidirectional

The forum for ZeosLib 7.2 Report problems. Ask for help, post proposals for the new version and Zeoslib 7.2 features here. This is a forum that will be edited once the 7.2.x version goes into RC/stable!!

My personal intention for 7.2 is to speed up the internals as optimal a possible for all IDE's. Hope you can help?! Have fun with testing 7.2
Post Reply
serbod
Junior Boarder
Junior Boarder
Posts: 27
Joined: 27.12.2012, 09:31

TZCachedResultSet - Read-only unidirectional

Post by serbod »

TZCachedResultSet is not optimized for read-only unidirectinal access, so it not applicable to very large (millions rows) results. And it only ResultSet for some database types (SQLite, MySQL, PostgreSQL).

I suggest some tweaks:

unit ZDbcCachedResultSet;

Code: Select all

  TZAbstractCachedResultSet = class (TZAbstractResultSet, IZCachedResultSet)
  private
    FFetchedRow: PZRowBuffer; // buffer for last fetched row
//...
    

procedure TZAbstractCachedResultSet.Close;
//...
  if Assigned(FRowAccessor) then
  begin
    if (ResultSetType = rtForwardOnly) and Assigned(FFetchedRow) then
    begin
      // dispose previous row buffer
      FRowAccessor.DisposeBuffer(FFetchedRow);
      FFetchedRow := nil;
    end;
//...

function TZAbstractCachedResultSet.MoveAbsolute(Row: Integer): Boolean;
//...
    if (Row >= 1) and (Row <= LastRowNo) then
    begin
      Result := True;
      if (ResultSetType = rtForwardOnly) then
        FSelectedRow := FFetchedRow
      else
        FSelectedRow := PZRowBuffer(FRowsList[Row - 1]);
      RowAccessor.RowBuffer := FSelectedRow;
//...

function TZAbstractCachedResultSet.RowUpdated: Boolean;
function TZAbstractCachedResultSet.RowInserted: Boolean;
function TZAbstractCachedResultSet.RowDeleted: Boolean;
//...
  if (RowNo >= 1) and (RowNo <= LastRowNo) then
  begin
    if (ResultSetType = rtForwardOnly) then
      CurrentRow := FFetchedRow
    else
      CurrentRow := PZRowBuffer(FRowsList[RowNo - 1]);
    Result := Assigned(CurrentRow) and (CurrentRow^.UpdateType = utModified);
    Result := Assigned(CurrentRow) and (CurrentRow^.UpdateType = utInserted);
    Result := Assigned(CurrentRow) and (CurrentRow^.UpdateType = utDeleted);
//...

function TZCachedResultSet.Fetch: Boolean;
//...
  TempRow := RowAccessor.RowBuffer;
  try
    if (ResultSetType = rtForwardOnly) and Assigned(FFetchedRow) then
    begin
      // dispose previous row buffer
      RowAccessor.DisposeBuffer(FFetchedRow);
      FFetchedRow := nil;
    end;
//...

    if (ResultSetType = rtForwardOnly) then
    begin
      FFetchedRow := RowAccessor.RowBuffer;
      LastRowNo := LastRowNo + 1;
    end
    else
    begin
      RowsList.Add(RowAccessor.RowBuffer);
      LastRowNo := RowsList.Count;
    end;
//...


unit ZDbcSqLiteStatement;

Code: Select all

function TZSQLiteStatement.CreateResultSet()
function TZSQLiteCAPIPreparedStatement.CreateResultSet()
//...
  if Self.ResultSetType <> rtForwardOnly then
  begin
    { Fetches all rows to prevent blocking. }
    CachedResultSet.SetType(rtScrollInsensitive);
    CachedResultSet.Last;
    CachedResultSet.BeforeFirst;
  end;
  CachedResultSet.SetConcurrency(GetResultSetConcurrency);
//...
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1956
Joined: 17.01.2011, 14:17

Re: TZCachedResultSet - Read-only unidirectional

Post by marsupilami »

Hello Serbod,

honestly I don't understand your approach. If you need a forward only result set why don't you simply set ResultSetConcurrency to rcReadOnly and the result set type to rtForwardOnly? In that case the sqlite driver will gladly return the native result set to you. The same should be true for all other drivers.

With best regards,

Jan
serbod
Junior Boarder
Junior Boarder
Posts: 27
Joined: 27.12.2012, 09:31

Re: TZCachedResultSet - Read-only unidirectional

Post by serbod »

Sorry, I write to wrong thread, my zeosdbo version is 7.1.4 (stable)

I need to disable cashing of whole result table. It impossible for TZCachedResultSet, by design. It use TList for every result record with RowNum as index. And rcReadOnly and rtForwardOnly do not change that behavior.
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1956
Joined: 17.01.2011, 14:17

Re: TZCachedResultSet - Read-only unidirectional

Post by marsupilami »

Hello Serbod,

you are right, Zeos 7.1 doesn't contain that code. But Zeos 7.1 will only see bugfixes and your suggestions don't fall in that category. Also I am not sure what impact that would have on other drivers in Zeos 7.1. I suggest, you move on to Zeos 7.2 from SVN. This is almost stable and has seen loads of bugfixes that didn't go into 7.1 besides having a lot of improvements when it comes to speed. Honestly the only reason for it not being declared stable yet is that nobody currently has the time to create a release. If for some reason you really have to stay witz Zeos 7.1 I suggest you copy the code for getting the native result set from Zeos 7.2. It is a simple if statement, that checks if a forward only read only result set is expected - if yes, the native result set is returned, if no the cached result set is returned.

With best regards,

Jan
Post Reply