我需要应用更新(ClientDataSet.ApplyUpdates)以按指定顺序应用: - 首先删除 - 修改为秒 - 插入第三个
它们按照完成的顺序应用。
答案 0 :(得分:0)
请参阅KTDataComponents以了解如何实现这一目标
除此之外,我有时通过切换到提供者端的OnUpdateData事件处理程序中的特定索引来形成所需的更新顺序。为了不破坏三角洲处理,必须使用几个技巧,但这是非常可行的
procedure TLogResolver.LogUpdateRecord(Tree: TUpdateTree);
var
I: Integer;
CurVal: Variant;
fld: TField;
SaveRecNo: Integer;
OldIndexName: WideString;
OldIndexFieldNames: WideString;
begin
if(TClientDataSet(Tree.Delta).IndexName<>'')or(TClientDataSet(Tree.Delta).IndexFieldNames<>'') then begin
OldIndexName:=TClientDataSet(Tree.Delta).IndexName;
OldIndexFieldNames:=TClientDataSet(Tree.Delta).IndexFieldNames;
SaveRecNo:=Tree.Delta.RecNo;
Tree.Delta.Edit; // vavan
for I := 0 to Tree.Delta.FieldCount - 1 do begin
fld:=Tree.Delta.Fields[I];
{ Blobs, Bytes and VarBytes are not included in result packet }
if {(fld.IsBlob) or} (fld.DataType in [ftBytes, ftVarBytes]) then // vavan allowed blobs
continue;
CurVal := fld.NewValue;
if not VarIsClear(CurVal) then begin
fld.Value:=CurVal; { TODO -ovavan -cSIC! : edit delta }
end;
end;
Tree.Delta.Post; // vavan
TClientDataSet(Tree.Delta).IndexName:=''; { TODO -ovavan -cSIC! : reset delta index to get correct original recno in order not to break reconcilation mechanism }
end;
try
Tree.ErrorDS.IndexFieldNames:='ERROR_RECORDNO';
// Tree.InitErrorPacket(nil, rrApply);
TreeInitErrorPacket(Tree,nil, rrApply);
for I := 0 to TVPacketDataSet(Tree.Delta).NewValueFields.Count - 1 do
begin
fld:=TVPacketDataSet(Tree.Delta).NewValueFields[i];
{ Blobs, Bytes and VarBytes are not included in result packet }
if {(Tree.Delta.Fields[I].IsBlob) or} // vavan allowed blobs
(fld.DataType in [ftBytes, ftVarBytes]) then
continue;
CurVal := fld.NewValue;
if not VarIsClear(CurVal) then begin { TODO 2 -ovavan -ccheck! : get rid of this check since we only process modified fields? }
Tree.ErrorDS.Fields[6+fld.Index].Value := CurVal; { TODO -ovavan -ccheck : ErrorDS fieldd structure is identical to delta but with extra 6 leading fields }
end;
end;
Tree.ErrorDS.Post;
finally
if(OldIndexName<>'')then begin
TClientDataSet(Tree.Delta).IndexName:=OldIndexName;
Tree.Delta.RecNo:=SaveRecNo;
end else
if(OldIndexFieldNames<>'')then begin
TClientDataSet(Tree.Delta).IndexFieldNames:=OldIndexFieldNames;
Tree.Delta.RecNo:=SaveRecNo;
end;
end;
end;