dataset-serialize
dataset-serialize copied to clipboard
How can I get the inserted, edited and deleted records of a dataset that is not a child dataset?
Hi,
I want to get only the inserted, edited and deleted records of the dataset (with CachedUpdates = True). The dataset does not have child datasets.
I am using a FDMemTable to get the changed records: inserted, edited and deleted, of the dataset with the following instructions: var booChildRecords, booOnlyUpdatedRecords : Boolean; jsonChangeViews : TJSONValue;
begin { parMTChangeViews : TFDMemTable that receives the FDMemTable (with CachedUpdates = True), that contains all the records inserted, updated and deleted. It is not a child dataset.}
booChildRecords := False; booOnlyUpdatedRecords := True; jsonChangeViews := parMTChangeViews.ToJSONArray(booOnlyUpdatedRecords, booChildRecords);
end;
The above-instruction only gets the inserted, edited and deleted records of a child dataset? How can I get the changed records of a dataset that is not a child dataset?
The above-instruction only gets the inserted, edited and deleted records of a child dataset?
R: Yes
The above-instruction only gets the inserted, edited and deleted records of a child dataset?
R: You can modify FilterChanges property of TFDMemTamble, before to call .ToJSONArray()
Hi,
Thank you very much for your answer.
I have changed the function TDataSetSerialize.DataSetToJSONArray(const ADataSet: TDataSet; const IsChild: Boolean): TJSONArray; of the DataSet.Serialize.Export.pas unit to get the inserted, edited and deleted records of a dataset that is not a child and a data set that is a child dataset.
Could you please tell me if that change works?
function TDataSetSerialize.DataSetToJSONArray(const ADataSet: TDataSet; const IsChild: Boolean): TJSONArray; var LBookMark: TBookmark; begin Result := TJSONArray.Create;
if ADataSet.IsEmpty then Exit;
try LBookMark := ADataSet.BookMark; ADataSet.First; while not ADataSet.Eof do begin {The original code only gets the inserted, edited and deleted records of the child datasets of the ADataSet.} { if IsChild and FOnlyUpdatedRecords then if (ADataSet.UpdateStatus = TUpdateStatus.usUnmodified) and not(HasChildModification(ADataSet)) then begin ADataSet.Next; Continue; end }
{I have changed the above-code to get the inserted, edited and deleted records of the ADataSet and of it's child datasets.}
if FOnlyUpdatedRecords then
begin
if (NOT(IsChild) and (ADataSet.UpdateStatus = TUpdateStatus.usUnmodified)) or
((IsChild) and (ADataSet.UpdateStatus = TUpdateStatus.usUnmodified) and
NOT(HasChildModification(ADataSet))) then
begin
ADataSet.Next;
Continue;
end;
end;
Result.AddElement(DataSetToJSONObject(ADataSet));
ADataSet.Next;
end;
finally if ADataSet.BookmarkValid(LBookMark) then ADataSet.GotoBookmark(LBookMark);
ADataSet.FreeBookmark(LBookMark);
end; end;
Thank you.
Dears, do you have any solution for FPC Lazarus? I've checked at DataSet.Serialize.Export source has a IF DEFINED to ignore "OnlyUpdatedRecords" param. Thanks
@rickdroio not until now...