Force the update of a field in reduced delta mode

hi Evgeny,
i’m using the code below to always make sure a field gets updated regardless of the fact if this field is changed or not, cause i want it to reflect the state in which the record exist when persisting

procedure datable.forcestateforprimkey(const pk:integer)
  for I := 0 to Self.Delta.Count-1 do
  begin
    if Self.Delta.Changes[I].ChangeType = ctUpdate then
    begin
      if (Self.Delta.Changes[I].OldValueByName[fld__primkey] = pk) AND
         (Self.Delta.Changes[I].OldValueByName[fld__State] = 
 Self.Delta.Changes[I].NewValueByName[fld__State]) then
        Self.Delta.Changes[I].OldValueByName[fld__State] := Null;
    end;
  end;

so i’m fiddling with the oldvalue of the field in question to get DA to recognise it as a a field that needs to be updated
servers side is set to upwherekeyonly off course

now can you confirm this code does what it’s meant to do?
(i have noticed some behavior in some records from about a year ago which let me believe this code didn’t do it’s job…)

so is it safe for me to assume that this will always make DA update the record or not?

Hi,

Make sure that old values for members of PK aren’t cleared, because Update delta command needs it:

UPDATE 
	[Customers] 
SET 
...
WHERE [CustomerID] = :OLD_CustomerID 

yep that i know :slight_smile:
but other then that this code should always update the field if this code has been executed right?

Hi,

yes, it should.
I would suggest to use ROVariantsEqual for comparing variants. just comparing values may be inaccurate

even if state is an integer field? (database wise it will never be null)

I don’t know what values are used in your table(s) so it’s just a general recommendation.

:+1: