* Moved FCurrentRecBuf from the index to TBufDataset itself

* Add new (inserted) records to all indexes

git-svn-id: trunk@10307 -
This commit is contained in:
joost 2008-02-11 22:06:00 +00:00
parent 52135af71f
commit 2220e453cf

View File

@ -126,7 +126,6 @@ type
FRecordArray : array of Pointer; FRecordArray : array of Pointer;
FLastRecInd : integer; FLastRecInd : integer;
{$ELSE} {$ELSE}
FCurrentRecBuf : PBufRecLinkItem;
FLastRecBuf : PBufRecLinkItem; FLastRecBuf : PBufRecLinkItem;
FFirstRecBuf : PBufRecLinkItem; FFirstRecBuf : PBufRecLinkItem;
{$ENDIF ARRAYBUF} {$ENDIF ARRAYBUF}
@ -145,6 +144,7 @@ type
FIndexesCount : integer; FIndexesCount : integer;
FCurrentIndex : PBufIndex; FCurrentIndex : PBufIndex;
FCurrentRecBuf : PBufRecLinkItem;
FFilterBuffer : pchar; FFilterBuffer : pchar;
FBRecordCount : integer; FBRecordCount : integer;
@ -491,7 +491,7 @@ begin
// Set FirstRecBuf and FCurrentRecBuf // Set FirstRecBuf and FCurrentRecBuf
AIndex.FFirstRecBuf:=FIndexes[0].FFirstRecBuf; AIndex.FFirstRecBuf:=FIndexes[0].FFirstRecBuf;
AIndex.FCurrentRecBuf:=AIndex.FFirstRecBuf; FCurrentRecBuf:=AIndex.FFirstRecBuf;
// Link in the FLastRecBuf that belongs to this index // Link in the FLastRecBuf that belongs to this index
PCurRecLinkItem[AIndex.IndNr].next:=AIndex.FLastRecBuf; PCurRecLinkItem[AIndex.IndNr].next:=AIndex.FLastRecBuf;
AIndex.FLastRecBuf[AIndex.IndNr].prior:=PCurRecLinkItem; AIndex.FLastRecBuf[AIndex.IndNr].prior:=PCurRecLinkItem;
@ -653,8 +653,8 @@ begin
begin begin
FFirstRecBuf := pointer(IntAllocRecordBuffer); FFirstRecBuf := pointer(IntAllocRecordBuffer);
FLastRecBuf := FFirstRecBuf; FLastRecBuf := FFirstRecBuf;
FCurrentRecBuf := FLastRecBuf;
end; end;
FCurrentRecBuf := FCurrentIndex^. FLastRecBuf;
{$ELSE} {$ELSE}
for IndexNr:=0 to FIndexesCount-1 do with FIndexes[IndexNr] do for IndexNr:=0 to FIndexesCount-1 do with FIndexes[IndexNr] do
begin begin
@ -964,7 +964,6 @@ begin
for i := 0 to FIndexesCount-1 do for i := 0 to FIndexesCount-1 do
if SameText(FIndexes[i].Name,AValue) then if SameText(FIndexes[i].Name,AValue) then
begin begin
FIndexes[i].FCurrentRecBuf := FCurrentIndex^.FCurrentRecBuf;
FCurrentIndex:=@FIndexes[i]; FCurrentIndex:=@FIndexes[i];
if active then Resync([rmCenter]); if active then Resync([rmCenter]);
exit; exit;
@ -987,7 +986,7 @@ begin
{$IFDEF ARRAYBUF} {$IFDEF ARRAYBUF}
FCurrentIndex^.FCurrentRecInd:=GetRecordFromBookmark(PBufBookmark(Buffer + FRecordSize)^); FCurrentIndex^.FCurrentRecInd:=GetRecordFromBookmark(PBufBookmark(Buffer + FRecordSize)^);
{$ELSE} {$ELSE}
FCurrentIndex^.FCurrentRecBuf := PBufBookmark(Buffer + FRecordSize)^.BookmarkData; FCurrentRecBuf := PBufBookmark(Buffer + FRecordSize)^.BookmarkData;
{$ENDIF} {$ENDIF}
end; end;
@ -1026,7 +1025,7 @@ begin
{$IFDEF ARRAYBUF} {$IFDEF ARRAYBUF}
FCurrentIndex^.FCurrentRecInd:=GetRecordFromBookmark(PBufBookmark(ABookmark)^); FCurrentIndex^.FCurrentRecInd:=GetRecordFromBookmark(PBufBookmark(ABookmark)^);
{$ELSE} {$ELSE}
FCurrentIndex^.FCurrentRecBuf := pointer(ABookmark^); FCurrentRecBuf := pointer(ABookmark^);
{$ENDIF} {$ENDIF}
end; end;
@ -1215,7 +1214,7 @@ begin
if not ((x=1) and (FIndexes[1].FieldsName='')) then if not ((x=1) and (FIndexes[1].FieldsName='')) then
begin begin
BuildIndex(FIndexes[x]); BuildIndex(FIndexes[x]);
FIndexes[x].FCurrentRecBuf:=FIndexes[x].FFirstRecBuf; FCurrentRecBuf:=FCurrentIndex^.FFirstRecBuf;
end; end;
end; end;
Exit; Exit;
@ -1367,10 +1366,10 @@ begin
InternalSetToRecord(ActiveBuffer); InternalSetToRecord(ActiveBuffer);
{$IFNDEF ARRAYBUF} {$IFNDEF ARRAYBUF}
// Remove the record from all active indexes // Remove the record from all active indexes
RemoveRecordFromIndex(FIndexes[0].FCurrentRecBuf,FIndexes[0]); RemoveRecordFromIndex(FCurrentRecBuf,FIndexes[0]);
if FCurrentIndex=@FIndexes[1] then StartInd := 1 else StartInd := 2; if FCurrentIndex=@FIndexes[1] then StartInd := 1 else StartInd := 2;
for i := StartInd to FIndexesCount-1 do for i := StartInd to FIndexesCount-1 do
RemoveRecordFromIndex(FIndexes[i].FCurrentRecBuf,FIndexes[i]); RemoveRecordFromIndex(FCurrentRecBuf,FIndexes[i]);
{$ENDIF} {$ENDIF}
if not GetRecordUpdateBuffer then if not GetRecordUpdateBuffer then
@ -1547,7 +1546,7 @@ begin
{$ELSE} {$ELSE}
CheckBrowseMode; CheckBrowseMode;
StoreRecBuf := FCurrentIndex^.FCurrentRecBuf; StoreRecBuf := FCurrentRecBuf;
r := 0; r := 0;
FailedCount := 0; FailedCount := 0;
@ -1615,7 +1614,7 @@ begin
SetLength(FUpdateBlobBuffers,0); SetLength(FUpdateBlobBuffers,0);
end; end;
FCurrentIndex^.FCurrentRecBuf := StoreRecBuf; FCurrentRecBuf := StoreRecBuf;
Resync([]); Resync([]);
end; end;
{$ENDIF} {$ENDIF}
@ -1666,7 +1665,7 @@ begin
begin begin
if GetBookmarkFlag(ActiveBuffer) = bfEOF then if GetBookmarkFlag(ActiveBuffer) = bfEOF then
// Append // Append
with FCurrentIndex^ do with FIndexes[0] do
{$IFDEF ARRAYBUF} {$IFDEF ARRAYBUF}
FCurrentRecInd := FLastRecInd FCurrentRecInd := FLastRecInd
{$ELSE} {$ELSE}
@ -1678,7 +1677,7 @@ begin
// inserted // inserted
InternalSetToRecord(ActiveBuffer); InternalSetToRecord(ActiveBuffer);
with FCurrentIndex^ do with FIndexes[0] do
begin begin
{$IFDEF ARRAYBUF} {$IFDEF ARRAYBUF}
inc(FLastRecInd); inc(FLastRecInd);
@ -1688,8 +1687,14 @@ begin
FRecordArray[FCurrentRecInd]:=pointer(IntAllocRecordBuffer); FRecordArray[FCurrentRecInd]:=pointer(IntAllocRecordBuffer);
{$ELSE} {$ELSE}
// Create the new record buffer // Create the new record buffer
AddRecordToIndex(PBufRecLinkItem(IntAllocRecordBuffer),FCurrentRecBuf,FCurrentIndex^); AddRecordToIndex(PBufRecLinkItem(IntAllocRecordBuffer),FCurrentRecBuf,FIndexes[0]);
FCurrentRecBuf := FCurrentRecBuf^.prior; FCurrentRecBuf := FCurrentRecBuf[IndNr].prior;
// Add the record to the other indexes
for i := 1 to FIndexesCount-1 do if ((i>1) or (@FIndexes[i]=FCurrentIndex)) then
begin
AddRecordToIndex(FCurrentRecBuf,FIndexes[i].FLastRecBuf,FIndexes[i]);
end;
{$ENDIF} {$ENDIF}
end; end;
@ -1699,7 +1704,7 @@ begin
{$IFDEF ARRAYBUF} {$IFDEF ARRAYBUF}
BookmarkData := FCurrentIndex^.FCurrentRecInd; BookmarkData := FCurrentIndex^.FCurrentRecInd;
{$ELSE} {$ELSE}
BookmarkData := FCurrentIndex^.FCurrentRecBuf; BookmarkData := FCurrentRecBuf;
{$ENDIF} {$ENDIF}
BookmarkFlag := bfInserted; BookmarkFlag := bfInserted;
end; end;
@ -1714,15 +1719,15 @@ begin
FCurrentUpdateBuffer := length(FUpdateBuffer); FCurrentUpdateBuffer := length(FUpdateBuffer);
SetLength(FUpdateBuffer,FCurrentUpdateBuffer+1); SetLength(FUpdateBuffer,FCurrentUpdateBuffer+1);
{$IFDEF ARRAYBUF}
with FCurrentIndex^ do with FCurrentIndex^ do
begin begin
{$IFDEF ARRAYBUF}
FUpdateBuffer[FCurrentUpdateBuffer].Bookmark.BookmarkData := FCurrentRecInd; FUpdateBuffer[FCurrentUpdateBuffer].Bookmark.BookmarkData := FCurrentRecInd;
FUpdateBuffer[FCurrentUpdateBuffer].Bookmark.BookMarkBuf := FRecordArray[FCurrentRecInd]; FUpdateBuffer[FCurrentUpdateBuffer].Bookmark.BookMarkBuf := FRecordArray[FCurrentRecInd];
end;
{$ELSE} {$ELSE}
FUpdateBuffer[FCurrentUpdateBuffer].BookmarkData := FCurrentRecBuf; FUpdateBuffer[FCurrentUpdateBuffer].BookmarkData := FCurrentRecBuf;
{$ENDIF} {$ENDIF}
end;
if state = dsEdit then if state = dsEdit then
begin begin
@ -1740,8 +1745,8 @@ begin
FUpdateBuffer[FCurrentUpdateBuffer].UpdateKind := ukInsert; FUpdateBuffer[FCurrentUpdateBuffer].UpdateKind := ukInsert;
end; end;
with FCurrentIndex^ do
{$IFDEF ARRAYBUF} {$IFDEF ARRAYBUF}
with FIndexes[0] do
move(ActiveBuffer^,FRecordArray[FCurrentRecInd]^,FRecordSize); move(ActiveBuffer^,FRecordArray[FCurrentRecInd]^,FRecordSize);
{$ELSE} {$ELSE}
CurrBuff := pchar(FCurrentRecBuf); CurrBuff := pchar(FCurrentRecBuf);
@ -2103,7 +2108,7 @@ begin
begin begin
FIndexes[FIndexesCount-1].FFirstRecBuf := pointer(IntAllocRecordBuffer); FIndexes[FIndexesCount-1].FFirstRecBuf := pointer(IntAllocRecordBuffer);
FIndexes[FIndexesCount-1].FLastRecBuf := FIndexes[FIndexesCount-1].FFirstRecBuf; FIndexes[FIndexesCount-1].FLastRecBuf := FIndexes[FIndexesCount-1].FFirstRecBuf;
FIndexes[FIndexesCount-1].FCurrentRecBuf := FIndexes[FIndexesCount-1].FLastRecBuf; FCurrentRecBuf := FIndexes[FIndexesCount-1].FLastRecBuf;
BuildIndex(FIndexes[FIndexesCount-1]); BuildIndex(FIndexes[FIndexesCount-1]);
end end
{$IFNDEF ARRAYBUF} {$IFNDEF ARRAYBUF}