mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-06-03 08:39:44 +02:00
* Refactored: extracted AddRecordToIndex
git-svn-id: trunk@10242 -
This commit is contained in:
parent
aafabe4bb2
commit
6a4007d446
@ -168,6 +168,8 @@ type
|
|||||||
FBlobBuffers : array of PBlobBuffer;
|
FBlobBuffers : array of PBlobBuffer;
|
||||||
FUpdateBlobBuffers: array of PBlobBuffer;
|
FUpdateBlobBuffers: array of PBlobBuffer;
|
||||||
|
|
||||||
|
procedure AddRecordToIndex(ANewRecord, ABeforeRecord: PBufRecLinkItem;
|
||||||
|
var AIndex: TBufIndex);
|
||||||
procedure FetchAll;
|
procedure FetchAll;
|
||||||
procedure BuildIndex(var AIndex : TBufIndex);
|
procedure BuildIndex(var AIndex : TBufIndex);
|
||||||
function GetIndexDefs : TIndexDefs;
|
function GetIndexDefs : TIndexDefs;
|
||||||
@ -1686,18 +1688,8 @@ begin
|
|||||||
FRecordArray[FCurrentRecInd]:=pointer(IntAllocRecordBuffer);
|
FRecordArray[FCurrentRecInd]:=pointer(IntAllocRecordBuffer);
|
||||||
{$ELSE}
|
{$ELSE}
|
||||||
// Create the new record buffer
|
// Create the new record buffer
|
||||||
tmpRecBuffer := FCurrentRecBuf^.prior;
|
AddRecordToIndex(PBufRecLinkItem(IntAllocRecordBuffer),FCurrentRecBuf,FCurrentIndex^);
|
||||||
|
|
||||||
FCurrentRecBuf^.prior := pointer(IntAllocRecordBuffer);
|
|
||||||
FCurrentRecBuf^.prior^.next := FCurrentRecBuf;
|
|
||||||
FCurrentRecBuf := FCurrentRecBuf^.prior;
|
FCurrentRecBuf := FCurrentRecBuf^.prior;
|
||||||
If assigned(tmpRecBuffer) then // if not, it's the first record
|
|
||||||
begin
|
|
||||||
FCurrentRecBuf^.prior := tmpRecBuffer;
|
|
||||||
tmpRecBuffer^.next := FCurrentRecBuf
|
|
||||||
end
|
|
||||||
else
|
|
||||||
FFirstRecBuf := FCurrentRecBuf;
|
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -1776,11 +1768,7 @@ begin
|
|||||||
tmpRecBuffer:=tmpRecBuffer[IndNr].prior;
|
tmpRecBuffer:=tmpRecBuffer[IndNr].prior;
|
||||||
end;
|
end;
|
||||||
// Place record at new position
|
// Place record at new position
|
||||||
PBufRecLinkItem(CurrBuff)[IndNr].prior:=tmpRecBuffer[IndNr].prior;
|
AddRecordToIndex(PBufRecLinkItem(CurrBuff),tmpRecBuffer,FIndexes[i]);
|
||||||
PBufRecLinkItem(CurrBuff)[IndNr].Next:=tmpRecBuffer;
|
|
||||||
|
|
||||||
PBufRecLinkItem(CurrBuff)[IndNr].Prior[IndNr].next:=PBufRecLinkItem(CurrBuff);
|
|
||||||
PBufRecLinkItem(CurrBuff)[IndNr].next[IndNr].prior:=PBufRecLinkItem(CurrBuff);
|
|
||||||
end
|
end
|
||||||
else if (PBufRecLinkItem(CurrBuff)[IndNr].next <> FIndexes[i].FLastRecBuf) and
|
else if (PBufRecLinkItem(CurrBuff)[IndNr].next <> FIndexes[i].FLastRecBuf) and
|
||||||
(IndexCompareRecords(CurrBuff,PBufRecLinkItem(CurrBuff)[FIndexes[i].IndNr].next,FIndexes[i].DBCompareStruct) > 0) then
|
(IndexCompareRecords(CurrBuff,PBufRecLinkItem(CurrBuff)[FIndexes[i].IndNr].next,FIndexes[i].DBCompareStruct) > 0) then
|
||||||
@ -1789,17 +1777,16 @@ begin
|
|||||||
RemoveRecordFromIndex(PBufRecLinkItem(CurrBuff),FIndexes[i]);
|
RemoveRecordFromIndex(PBufRecLinkItem(CurrBuff),FIndexes[i]);
|
||||||
// iterate to new position
|
// iterate to new position
|
||||||
tmpRecBuffer:=PBufRecLinkItem(CurrBuff)[IndNr].next;
|
tmpRecBuffer:=PBufRecLinkItem(CurrBuff)[IndNr].next;
|
||||||
while (tmpRecBuffer[IndNr].next<>FIndexes[i].FLastRecBuf) and
|
while (tmpRecBuffer<>FIndexes[i].FLastRecBuf) and
|
||||||
(IndexCompareRecords(CurrBuff,tmpRecBuffer[indnr].next,FIndexes[i].DBCompareStruct) > 0) do
|
(IndexCompareRecords(CurrBuff,tmpRecBuffer[indnr].next,FIndexes[i].DBCompareStruct) > 0) do
|
||||||
begin
|
begin
|
||||||
tmpRecBuffer:=tmpRecBuffer[IndNr].next;
|
tmpRecBuffer:=tmpRecBuffer[IndNr].next;
|
||||||
end;
|
end;
|
||||||
|
// The record should be added _after_ the the current record, not before
|
||||||
|
if (tmpRecBuffer<>FIndexes[i].FLastRecBuf) then
|
||||||
|
tmpRecBuffer:=tmpRecBuffer[IndNr].next;
|
||||||
// Place record at new position
|
// Place record at new position
|
||||||
PBufRecLinkItem(CurrBuff)[IndNr].next:=tmpRecBuffer[IndNr].next;
|
AddRecordToIndex(PBufRecLinkItem(CurrBuff),tmpRecBuffer,FIndexes[i]);
|
||||||
PBufRecLinkItem(CurrBuff)[IndNr].prior:=tmpRecBuffer;
|
|
||||||
|
|
||||||
PBufRecLinkItem(CurrBuff)[IndNr].Prior[IndNr].next:=PBufRecLinkItem(CurrBuff);
|
|
||||||
PBufRecLinkItem(CurrBuff)[IndNr].next[IndNr].prior:=PBufRecLinkItem(CurrBuff);
|
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
@ -2209,6 +2196,23 @@ begin
|
|||||||
ARecord[IndNr].next[IndNr].prior := ARecord[IndNr].prior;
|
ARecord[IndNr].next[IndNr].prior := ARecord[IndNr].prior;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TBufDataset.AddRecordToIndex(ANewRecord, ABeforeRecord: PBufRecLinkItem;
|
||||||
|
var AIndex: TBufIndex);
|
||||||
|
// Add a record to the index before the current record.
|
||||||
|
begin
|
||||||
|
with AIndex do
|
||||||
|
begin
|
||||||
|
ANewRecord[IndNr].prior:=ABeforeRecord[IndNr].prior;
|
||||||
|
ANewRecord[IndNr].Next:=ABeforeRecord;
|
||||||
|
|
||||||
|
if ABeforeRecord=FFirstRecBuf then
|
||||||
|
FFirstRecBuf:=ANewRecord
|
||||||
|
else
|
||||||
|
ANewRecord[IndNr].Prior[IndNr].next:=ANewRecord;
|
||||||
|
ANewRecord[IndNr].next[IndNr].prior:=ANewRecord;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
{$IFDEF ARRAYBUF}
|
{$IFDEF ARRAYBUF}
|
||||||
function TBufDataset.GetRecordFromBookmark(ABookMark: TBufBookmark) : integer;
|
function TBufDataset.GetRecordFromBookmark(ABookMark: TBufBookmark) : integer;
|
||||||
begin
|
begin
|
||||||
|
Loading…
Reference in New Issue
Block a user