Is TField.OldValue not supported for cachedupdates?

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
Soner
Junior Boarder
Junior Boarder
Posts: 27
Joined: 12.02.2017, 17:00

Is TField.OldValue not supported for cachedupdates?

Post by Soner »

When I set TZQuery.CachedUpdates to true then TField.OldValue returns incorrect values. Is it not supported for cachedupdates?
I use Lazarus 1.8.5 fpc 3.0.4. and sqlite
Same result with Turbo Delphi and Firebird-DB.

I put one example for lazarus and one for turbo delphi.
You do not have the required permissions to view the files attached to this post.
Soner
Junior Boarder
Junior Boarder
Posts: 27
Joined: 12.02.2017, 17:00

Re: Is TField.OldValue not supported for cachedupdates?

Post by Soner »

Or I don't really need the old value. Is there any way to detect if the field is changed for chachedupdates?
I want indicate changed values in TDBGrid.
Soner
Junior Boarder
Junior Boarder
Posts: 27
Joined: 12.02.2017, 17:00

Re: Is TField.OldValue not supported for cachedupdates?

Post by Soner »

I think I found one bug and the reason for incorrect oldvalues.
Look my comments in this code.:

Code: Select all

// from ZDbcCachedResultSet.pas

procedure TZAbstractCachedResultSet.MoveToInitialRow;
var
  Index: Integer;
begin
  CheckClosed;
  if (RowNo >= 1) and (RowNo <= LastRowNo) and (FSelectedRow <> nil) then
  begin
    Index := LocateRow(FInitialRowsList, FSelectedRow.Index);
    if Index >= 0 then
    begin
      FSelectedRow := FInitialRowsList[Index];
      FRowAccessor.RowBuffer := FSelectedRow;
    end;
     // my comment start .....................
     // When Index <0 is then FRowAccessor.RowBuffer showing wrong buffer. 
     // but when i add this: 
     //    else FRowAccessor.RowBuffer := nil;
     // then i get error when the row is not changed/edited. THis is o.k. 
     // I can catch the error in my application to know that there is no changes.
     
     // EDIT:    FORGET THIS PART  THIS IS TDBGRID ISSUE FROM LAZARUS..................
     // But this works only good, when you scroll dataset between not changed rows and changed rows.
     // When you scroll from changed to not changed and reverse then the oldvalues are in not changed row wrong.
     // To Inspect this start my example and change some value from last row 
     // then scroll between rows look at the memo.     
     //.............EDIT END
     
     // ....................... my comment  end
     
  end
  else
    FRowAccessor.RowBuffer := nil;
end; 
Soner
Junior Boarder
Junior Boarder
Posts: 27
Joined: 12.02.2017, 17:00

Re: Is TField.OldValue not supported for cachedupdates?

Post by Soner »

If someone interested I found better way. Add this to ZDbcCachedResultSet.pas:

Code: Select all

function TZAbstractCachedResultSet.GetOldValAsString(ARecNo, AColumnIndex: Integer; var AIsNull: Boolean): String; //20180917 soner for oldvalue
var
  aIndex: Integer;
  aOldRowAccessor: TZRowAccessor;
begin
  CheckClosed;
  if (ARecNo > 0) and (ARecNo <= LastRowNo)  then
  begin
    aIndex := LocateRow(FInitialRowsList, ARecNo-1);

    if aIndex >= 0 then
    begin
       aOldRowAccessor:=TZRowAccessor.Create(ColumnsInfo, ConSettings);
     try
       FSelectedRow := FInitialRowsList[aIndex];
       aOldRowAccessor.RowBuffer := FInitialRowsList[aIndex];

       Result:= aOldRowAccessor.GetString(AColumnIndex+1,AIsNull);
      finally
        aOldRowAccessor.Free;
      end;
    end
    else begin
      AIsNull:=true;
      Result:='';
    end;
  end
  else begin
    AIsNull:=true;
    Result:='';
    //Result:=RowNo.ToString+'/'+LastRowNo.ToString; //test
  end;
end;
Post Reply