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