procedure TCustomBufDataset.GetDatasetPacket(AWriter: TDataPacketReader);
procedure StoreUpdateBuffer(AUpdBuffer : TRecUpdateBuffer; var ARowState: TRowState);
var AThisRowState : TRowState;
AStoreUpdBuf : Integer;
begin
if AUpdBuffer.UpdateKind = ukModify then
begin
AThisRowState := [rsvOriginal];
ARowState:=[rsvUpdated];
end
else if AUpdBuffer.UpdateKind = ukDelete then
begin
AStoreUpdBuf:=FCurrentUpdateBuffer;
if GetRecordUpdateBuffer(AUpdBuffer.BookmarkData,True,False) then
repeat
if CurrentIndexBuf.SameBookmarks(@FUpdateBuffer[FCurrentUpdateBuffer].NextBookmarkData, @AUpdBuffer.BookmarkData) then
StoreUpdateBuffer(FUpdateBuffer[FCurrentUpdateBuffer], ARowState);
until not GetRecordUpdateBuffer(AUpdBuffer.BookmarkData,True,True);
FCurrentUpdateBuffer:=AStoreUpdBuf;
AThisRowState := [rsvDeleted];
end
else // ie: UpdateKind = ukInsert
ARowState := [rsvInserted];
FFilterBuffer:=AUpdBuffer.OldValuesBuffer;
// OldValuesBuffer is nil if the record is either inserted or inserted and then deleted
if assigned(FFilterBuffer) then
FDatasetReader.StoreRecord(AThisRowState,FCurrentUpdateBuffer);
end;
procedure HandleUpdateBuffersFromRecord(AFindNext : boolean; ARecBookmark : TBufBookmark; var ARowState: TRowState);
var StoreUpdBuf1,StoreUpdBuf2 : Integer;
begin
if not AFindNext then ARowState:=[];
if GetRecordUpdateBuffer(ARecBookmark,True,AFindNext) then
begin
if FUpdateBuffer[FCurrentUpdateBuffer].UpdateKind=ukDelete then
begin
StoreUpdBuf1:=FCurrentUpdateBuffer;
HandleUpdateBuffersFromRecord(True,ARecBookmark,ARowState);
StoreUpdBuf2:=FCurrentUpdateBuffer;
FCurrentUpdateBuffer:=StoreUpdBuf1;
StoreUpdateBuffer(FUpdateBuffer[StoreUpdBuf1], ARowState);
FCurrentUpdateBuffer:=StoreUpdBuf2;
end
else
begin
StoreUpdateBuffer(FUpdateBuffer[FCurrentUpdateBuffer], ARowState);
HandleUpdateBuffersFromRecord(True,ARecBookmark,ARowState);
end;
end
end;
var ScrollResult : TGetResult;
SavedState : TDataSetState;
ABookMark : PBufBookmark;
ATBookmark : TBufBookmark;
RowState : TRowState;
begin
FDatasetReader := AWriter;
try
// CheckActive;
ABookMark:=@ATBookmark;
FDatasetReader.StoreFieldDefs(FAutoIncValue);
SavedState:=SetTempState(dsFilter);
ScrollResult:=CurrentIndexBuf.ScrollFirst;
while ScrollResult=grOK do
begin
RowState:=[];
CurrentIndexBuf.StoreCurrentRecIntoBookmark(ABookmark);
// updates related to current record are stored first
// ML - This actually causes the ORIGINAL record to be saved (see line 26-29 above)
HandleUpdateBuffersFromRecord(False,ABookmark^,RowState);
// now store current record
// ML - Now the modified data is stored
FFilterBuffer:=CurrentIndexBuf.CurrentBuffer;
if RowState=[] then
FDatasetReader.StoreRecord([])
else
// ML - TCSVDataPacketReader.StoreRecord ignores parameters (see csvdataset.pp line 271)
FDatasetReader.StoreRecord(RowState,FCurrentUpdateBuffer);
ScrollResult:=CurrentIndexBuf.ScrollForward;
if ScrollResult<>grOK then
begin
if getnextpacket>0 then
ScrollResult := CurrentIndexBuf.ScrollForward;
end;
end;
// There could be an update buffer linked to the last (spare) record
CurrentIndexBuf.StoreSpareRecIntoBookmark(ABookmark);
HandleUpdateBuffersFromRecord(False,ABookmark^,RowState);
RestoreState(SavedState);
FDatasetReader.FinalizeStoreRecords;
finally
FDatasetReader := nil;
end;
end;