mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-20 04:59:26 +02:00
fcl-db: bufdataset: when updates in update buffers are canceled, reverted records must be correctly restored to all active indexes not only in current (then other indexes remains in inconsistent state)
Bug #25314 git-svn-id: trunk@26093 -
This commit is contained in:
parent
6af4353933
commit
c16d232c3a
@ -474,7 +474,6 @@ type
|
||||
procedure FetchAll;
|
||||
procedure ProcessFieldsToCompareStruct(const AFields, ADescFields, ACInsFields: TList;
|
||||
const AIndexOptions: TIndexOptions; const ALocateOptions: TLocateOptions; out ACompareStruct: TDBCompareStruct);
|
||||
procedure BuildIndex(var AIndex : TBufIndex);
|
||||
function BufferOffset: integer;
|
||||
function GetIndexDefs : TIndexDefs;
|
||||
function GetCurrentBuffer: TRecordBuffer;
|
||||
@ -498,7 +497,11 @@ type
|
||||
procedure IntLoadRecordsFromFile;
|
||||
procedure CurrentRecordToBuffer(Buffer: TRecordBuffer);
|
||||
procedure SetBufUniDirectional(const AValue: boolean);
|
||||
// indexes handling
|
||||
procedure InitDefaultIndexes;
|
||||
procedure BuildIndex(var AIndex : TBufIndex);
|
||||
procedure BuildIndexes;
|
||||
procedure RemoveRecordFromIndexes(const ABookmark : TBufBookmark);
|
||||
protected
|
||||
function GetNewBlobBuffer : PBlobBuffer;
|
||||
function GetNewWriteBlobBuffer : PBlobBuffer;
|
||||
@ -534,7 +537,7 @@ type
|
||||
function IsCursorOpen: Boolean; override;
|
||||
function GetRecordCount: Longint; override;
|
||||
procedure ApplyRecUpdate(UpdateKind : TUpdateKind); virtual;
|
||||
procedure SetOnUpdateError(const aValue: TResolverErrorEvent);
|
||||
procedure SetOnUpdateError(const AValue: TResolverErrorEvent);
|
||||
procedure SetFilterText(const Value: String); override; {virtual;}
|
||||
procedure SetFiltered(Value: Boolean); override; {virtual;}
|
||||
procedure InternalRefresh; override;
|
||||
@ -797,6 +800,7 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
{ ---------------------------------------------------------------------
|
||||
TCustomBufDataset
|
||||
---------------------------------------------------------------------}
|
||||
@ -1089,6 +1093,22 @@ begin
|
||||
DblLinkIndex.FLastRecBuf[DblLinkIndex.IndNr].prior:=l;
|
||||
end;
|
||||
|
||||
procedure TCustomBufDataset.BuildIndexes;
|
||||
var i: integer;
|
||||
begin
|
||||
for i:=1 to FIndexesCount-1 do
|
||||
if (i<>1) or (FIndexes[i]=FCurrentIndex) then
|
||||
BuildIndex(FIndexes[i]);
|
||||
end;
|
||||
|
||||
procedure TCustomBufDataset.RemoveRecordFromIndexes(const ABookmark: TBufBookmark);
|
||||
var i: integer;
|
||||
begin
|
||||
for i:=0 to FIndexesCount-1 do
|
||||
if (i<>1) or (FIndexes[i]=FCurrentIndex) then
|
||||
FIndexes[i].RemoveRecordFromIndex(ABookmark);
|
||||
end;
|
||||
|
||||
function TCustomBufDataset.GetIndexDefs : TIndexDefs;
|
||||
|
||||
begin
|
||||
@ -1109,7 +1129,7 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
Function TCustomBufDataset.GetCanModify: Boolean;
|
||||
function TCustomBufDataset.GetCanModify: Boolean;
|
||||
begin
|
||||
Result:=not (UniDirectional or ReadOnly);
|
||||
end;
|
||||
@ -1954,11 +1974,7 @@ begin
|
||||
FAllPacketsFetched := True;
|
||||
// This code has to be placed elsewhere. At least it should also run when
|
||||
// the datapacket is loaded from file ... see IntLoadRecordsFromFile
|
||||
if FIndexesCount>0 then for x := 1 to FIndexesCount-1 do
|
||||
begin
|
||||
if not ((x=1) and (FIndexes[1].FieldsName='')) then
|
||||
BuildIndex(FIndexes[x]);
|
||||
end;
|
||||
BuildIndexes;
|
||||
Exit;
|
||||
end;
|
||||
|
||||
@ -2095,9 +2111,7 @@ begin
|
||||
// Remove the record from all active indexes
|
||||
FCurrentIndex.StoreCurrentRecIntoBookmark(@RemRecBookmrk);
|
||||
RemRec := FCurrentIndex.CurrentBuffer;
|
||||
for i := 0 to FIndexesCount-1 do
|
||||
if (i<>1) or (FIndexes[i]=FCurrentIndex) then
|
||||
FIndexes[i].RemoveRecordFromIndex(RemRecBookmrk);
|
||||
RemoveRecordFromIndexes(RemRecBookmrk);
|
||||
|
||||
if not GetActiveRecordUpdateBuffer then
|
||||
begin
|
||||
@ -2175,10 +2189,8 @@ var StoreRecBM : TBufBookmark;
|
||||
if GetRecordUpdateBuffer(Bm,True,False) then
|
||||
begin
|
||||
repeat
|
||||
if (FCurrentUpdateBuffer<>StoreUpdBuf) then
|
||||
begin
|
||||
CancelUpdBuffer(FUpdateBuffer[FCurrentUpdateBuffer]);
|
||||
end;
|
||||
if (FCurrentUpdateBuffer<>StoreUpdBuf) then
|
||||
CancelUpdBuffer(FUpdateBuffer[FCurrentUpdateBuffer]);
|
||||
until not GetRecordUpdateBuffer(Bm,True,True);
|
||||
end;
|
||||
FCurrentUpdateBuffer:=StoreUpdBuf;
|
||||
@ -2194,7 +2206,7 @@ var StoreRecBM : TBufBookmark;
|
||||
ScrollLast; // last record will be removed from index, so move to spare record
|
||||
StoreCurrentRecIntoBookmark(@StoreRecBM);
|
||||
end;
|
||||
FCurrentIndex.RemoveRecordFromIndex(Bm);
|
||||
RemoveRecordFromIndexes(Bm);
|
||||
FreeRecordBuffer(TmpBuf);
|
||||
dec(FBRecordCount);
|
||||
end;
|
||||
@ -2563,13 +2575,13 @@ begin
|
||||
Result := FOpen;
|
||||
end;
|
||||
|
||||
Function TCustomBufDataset.GetRecordCount: Longint;
|
||||
function TCustomBufDataset.GetRecordCount: Longint;
|
||||
|
||||
begin
|
||||
Result := FBRecordCount;
|
||||
end;
|
||||
|
||||
Function TCustomBufDataset.UpdateStatus: TUpdateStatus;
|
||||
function TCustomBufDataset.UpdateStatus: TUpdateStatus;
|
||||
|
||||
begin
|
||||
Result:=usUnmodified;
|
||||
@ -3052,9 +3064,7 @@ begin
|
||||
end;
|
||||
|
||||
// rebuild indexes
|
||||
for x:=1 to FIndexesCount-1 do
|
||||
if (x<>1) or (FIndexes[x]=FCurrentIndex) then
|
||||
BuildIndex(FIndexes[x]);
|
||||
BuildIndexes;
|
||||
end;
|
||||
|
||||
procedure TCustomBufDataset.DoFilterRecord(out Acceptable: Boolean);
|
||||
@ -3165,7 +3175,8 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
Function TCustomBufDataset.Locate(const KeyFields: string; const KeyValues: Variant; Options: TLocateOptions) : boolean;
|
||||
function TCustomBufDataset.Locate(const KeyFields: string;
|
||||
const KeyValues: Variant; Options: TLocateOptions): boolean;
|
||||
|
||||
var CurrLinkItem : PBufRecLinkItem;
|
||||
bm : TBufBookmark;
|
||||
@ -3916,6 +3927,7 @@ begin
|
||||
// Do nothing
|
||||
end;
|
||||
|
||||
|
||||
initialization
|
||||
setlength(RegisteredDatapacketReaders,0);
|
||||
finalization
|
||||
|
Loading…
Reference in New Issue
Block a user