Page 1 of 1

Is TField.OldValue not supported for cachedupdates?

Posted: 17.09.2018, 14:43
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.

Re: Is TField.OldValue not supported for cachedupdates?

Posted: 17.09.2018, 14:57
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.

Re: Is TField.OldValue not supported for cachedupdates?

Posted: 17.09.2018, 20:55
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; 

Re: Is TField.OldValue not supported for cachedupdates?

Posted: 17.09.2018, 21:51
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;