mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-29 21:43:30 +02:00
* Changes to be able to add an index to an open dataset. Added FMaxIndexesCount.
* Added dummy-BuildIndex git-svn-id: trunk@9610 -
This commit is contained in:
parent
2cc3f2ebf3
commit
5724713259
@ -131,6 +131,8 @@ type
|
|||||||
{$IFDEF ARRAYBUF}
|
{$IFDEF ARRAYBUF}
|
||||||
FInitialBuffers : integer;
|
FInitialBuffers : integer;
|
||||||
FGrowBuffer : integer;
|
FGrowBuffer : integer;
|
||||||
|
{$ELSE}
|
||||||
|
FMaxIndexesCount: integer;
|
||||||
{$ENDIF ARRAYBUF}
|
{$ENDIF ARRAYBUF}
|
||||||
|
|
||||||
FIndexesCount : integer;
|
FIndexesCount : integer;
|
||||||
@ -158,6 +160,7 @@ type
|
|||||||
FBlobBuffers : array of PBlobBuffer;
|
FBlobBuffers : array of PBlobBuffer;
|
||||||
FUpdateBlobBuffers: array of PBlobBuffer;
|
FUpdateBlobBuffers: array of PBlobBuffer;
|
||||||
|
|
||||||
|
procedure BuildIndex(AIndex : TBufIndex);
|
||||||
function GetIndexDefs : TIndexDefs;
|
function GetIndexDefs : TIndexDefs;
|
||||||
{$IFDEF ARRAYBUF}
|
{$IFDEF ARRAYBUF}
|
||||||
procedure AddRecordToIndex(var AIndex: TBufIndex; ARecBuf: pchar);
|
procedure AddRecordToIndex(var AIndex: TBufIndex; ARecBuf: pchar);
|
||||||
@ -282,6 +285,8 @@ begin
|
|||||||
{$IFDEF ARRAYBUF}
|
{$IFDEF ARRAYBUF}
|
||||||
FInitialBuffers:=10000;
|
FInitialBuffers:=10000;
|
||||||
FGrowBuffer:=1000;
|
FGrowBuffer:=1000;
|
||||||
|
{$ELSE}
|
||||||
|
FMaxIndexesCount:=2;
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
FIndexesCount:=0;
|
FIndexesCount:=0;
|
||||||
InternalAddIndex('DEFAULT_ORDER','');
|
InternalAddIndex('DEFAULT_ORDER','');
|
||||||
@ -309,6 +314,33 @@ begin
|
|||||||
inherited destroy;
|
inherited destroy;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TBufDataset.BuildIndex(AIndex: TBufIndex);
|
||||||
|
var PCurRecLinkItem : PBufRecLinkItem;
|
||||||
|
begin
|
||||||
|
// This simply copies the index...
|
||||||
|
{$IFNDEF ARRAYBUF}
|
||||||
|
PCurRecLinkItem:=FIndexes[0].FFirstRecBuf;
|
||||||
|
|
||||||
|
if PCurRecLinkItem <> FIndexes[0].FLastRecBuf then
|
||||||
|
begin
|
||||||
|
while PCurRecLinkItem^.next<>FIndexes[0].FLastRecBuf do
|
||||||
|
begin
|
||||||
|
PCurRecLinkItem:=PCurRecLinkItem^.next;
|
||||||
|
|
||||||
|
PCurRecLinkItem[AIndex.IndNr].next := PCurRecLinkItem[0].next;
|
||||||
|
PCurRecLinkItem[AIndex.IndNr].prior := PCurRecLinkItem[0].prior;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
// Set FirstRecBuf and FCurrentRecBuf
|
||||||
|
AIndex.FFirstRecBuf:=FIndexes[0].FFirstRecBuf;
|
||||||
|
AIndex.FCurrentRecBuf:=FIndexes[0].FCurrentRecBuf;
|
||||||
|
// Link in the FLastRecBuf that belongs to this index
|
||||||
|
PCurRecLinkItem[AIndex.IndNr].next:=AIndex.FLastRecBuf;
|
||||||
|
AIndex.FLastRecBuf:=PCurRecLinkItem;
|
||||||
|
{$ENDIF}
|
||||||
|
end;
|
||||||
|
|
||||||
function TBufDataset.GetIndexDefs : TIndexDefs;
|
function TBufDataset.GetIndexDefs : TIndexDefs;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
@ -339,7 +371,7 @@ begin
|
|||||||
{$IFDEF ARRAYBUF}
|
{$IFDEF ARRAYBUF}
|
||||||
result := AllocMem(FRecordsize);
|
result := AllocMem(FRecordsize);
|
||||||
{$ELSE}
|
{$ELSE}
|
||||||
result := AllocMem(FRecordsize+sizeof(TBufRecLinkItem)*FIndexesCount);
|
result := AllocMem(FRecordsize+sizeof(TBufRecLinkItem)*FMaxIndexesCount);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -597,7 +629,7 @@ begin
|
|||||||
with FCurrentIndex^ do
|
with FCurrentIndex^ do
|
||||||
move((FRecordArray[FCurrentRecInd])^,buffer^,FRecordSize);
|
move((FRecordArray[FCurrentRecInd])^,buffer^,FRecordSize);
|
||||||
{$ELSE}
|
{$ELSE}
|
||||||
move((pointer(FCurrentRecBuf)+sizeof(TBufRecLinkItem)*FIndexesCount)^,buffer^,FRecordSize);
|
move((pointer(FCurrentRecBuf)+sizeof(TBufRecLinkItem)*FMaxIndexesCount)^,buffer^,FRecordSize);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
|
||||||
GetCalcFields(Buffer);
|
GetCalcFields(Buffer);
|
||||||
@ -777,7 +809,7 @@ begin
|
|||||||
AIndex.FRecordArray[RecInd]:= ARecBuf;
|
AIndex.FRecordArray[RecInd]:= ARecBuf;
|
||||||
inc(AIndex.FLastRecInd)
|
inc(AIndex.FLastRecInd)
|
||||||
{$ELSE}
|
{$ELSE}
|
||||||
inc(NewValueBuf,sizeof(TBufRecLinkItem)*FIndexesCount);
|
inc(NewValueBuf,sizeof(TBufRecLinkItem)*FMaxIndexesCount);
|
||||||
CompBuf:=AIndex.FFirstRecBuf;
|
CompBuf:=AIndex.FFirstRecBuf;
|
||||||
|
|
||||||
cp := 1;
|
cp := 1;
|
||||||
@ -785,7 +817,7 @@ begin
|
|||||||
begin
|
begin
|
||||||
if AIndex.Fields.DataType = ftString then
|
if AIndex.Fields.DataType = ftString then
|
||||||
begin
|
begin
|
||||||
cp := CompareText0(pointer(NewValueBuf),pchar(CompBuf)+sizeof(TBufRecLinkItem)*FIndexesCount+FFieldBufPositions[AIndex.Fields.FieldNo-1],length(pchar(NewValueBuf)),[]);
|
cp := CompareText0(pointer(NewValueBuf),pchar(CompBuf)+sizeof(TBufRecLinkItem)*FMaxIndexesCount+FFieldBufPositions[AIndex.Fields.FieldNo-1],length(pchar(NewValueBuf)),[]);
|
||||||
if cp > 0 then
|
if cp > 0 then
|
||||||
CompBuf := CompBuf[AIndex.IndNr].next;
|
CompBuf := CompBuf[AIndex.IndNr].next;
|
||||||
end;
|
end;
|
||||||
@ -819,7 +851,7 @@ begin
|
|||||||
with FCurrentIndex^ do
|
with FCurrentIndex^ do
|
||||||
pb := pchar(FRecordArray[FLastRecInd]);
|
pb := pchar(FRecordArray[FLastRecInd]);
|
||||||
{$ELSE}
|
{$ELSE}
|
||||||
pb := pchar(pointer(FIndexes[0].FLastRecBuf)+sizeof(TBufRecLinkItem)*FIndexesCount);
|
pb := pchar(pointer(FIndexes[0].FLastRecBuf)+sizeof(TBufRecLinkItem)*FMaxIndexesCount);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
while ((i < FPacketRecords) or (FPacketRecords = -1)) and (loadbuffer(pb) = grOk) do
|
while ((i < FPacketRecords) or (FPacketRecords = -1)) and (loadbuffer(pb) = grOk) do
|
||||||
begin
|
begin
|
||||||
@ -847,7 +879,7 @@ begin
|
|||||||
|
|
||||||
FLastRecBuf := FLastRecBuf^.next;
|
FLastRecBuf := FLastRecBuf^.next;
|
||||||
|
|
||||||
pb := pchar(pointer(FLastRecBuf)+sizeof(TBufRecLinkItem)*FIndexesCount);
|
pb := pchar(pointer(FLastRecBuf)+sizeof(TBufRecLinkItem)*FMaxIndexesCount);
|
||||||
end;
|
end;
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
inc(i);
|
inc(i);
|
||||||
@ -952,7 +984,7 @@ begin
|
|||||||
result := false;
|
result := false;
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
currbuff := FUpdateBuffer[FCurrentUpdateBuffer].OldValuesBuffer+sizeof(TBufRecLinkItem)*FIndexesCount;
|
currbuff := FUpdateBuffer[FCurrentUpdateBuffer].OldValuesBuffer+sizeof(TBufRecLinkItem)*FMaxIndexesCount;
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
@ -1012,7 +1044,7 @@ begin
|
|||||||
{$IFDEF ARRAYBUF}
|
{$IFDEF ARRAYBUF}
|
||||||
CurrBuff := FRecordArray[FLastRecInd]
|
CurrBuff := FRecordArray[FLastRecInd]
|
||||||
{$ELSE}
|
{$ELSE}
|
||||||
CurrBuff := pointer(FLastRecBuf) + sizeof(TBufRecLinkItem)*FIndexesCount
|
CurrBuff := pointer(FLastRecBuf) + sizeof(TBufRecLinkItem)*FMaxIndexesCount
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
else
|
else
|
||||||
CurrBuff := GetCurrentBuffer;
|
CurrBuff := GetCurrentBuffer;
|
||||||
@ -1152,7 +1184,7 @@ begin
|
|||||||
FRecordArray[Bookmark.BookmarkData] := OldValuesBuffer;
|
FRecordArray[Bookmark.BookmarkData] := OldValuesBuffer;
|
||||||
end;
|
end;
|
||||||
{$ELSE}
|
{$ELSE}
|
||||||
move(pchar(OldValuesBuffer+sizeof(TBufRecLinkItem)*FIndexesCount)^,pchar(BookmarkData+sizeof(TBufRecLinkItem)*FIndexesCount)^,FRecordSize);
|
move(pchar(OldValuesBuffer+sizeof(TBufRecLinkItem)*FMaxIndexesCount)^,pchar(BookmarkData+sizeof(TBufRecLinkItem)*FMaxIndexesCount)^,FRecordSize);
|
||||||
FreeRecordBuffer(OldValuesBuffer);
|
FreeRecordBuffer(OldValuesBuffer);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
end
|
end
|
||||||
@ -1423,7 +1455,7 @@ begin
|
|||||||
{$IFDEF ARRAYBUF}
|
{$IFDEF ARRAYBUF}
|
||||||
move(FRecordArray[FCurrentRecInd]^,FUpdateBuffer[FCurrentUpdateBuffer].OldValuesBuffer^,FRecordSize);
|
move(FRecordArray[FCurrentRecInd]^,FUpdateBuffer[FCurrentUpdateBuffer].OldValuesBuffer^,FRecordSize);
|
||||||
{$ELSE}
|
{$ELSE}
|
||||||
move(FCurrentRecBuf^,FUpdateBuffer[FCurrentUpdateBuffer].OldValuesBuffer^,FRecordSize+sizeof(TBufRecLinkItem)*FIndexesCount);
|
move(FCurrentRecBuf^,FUpdateBuffer[FCurrentUpdateBuffer].OldValuesBuffer^,FRecordSize+sizeof(TBufRecLinkItem)*FMaxIndexesCount);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
FUpdateBuffer[FCurrentUpdateBuffer].UpdateKind := ukModify;
|
FUpdateBuffer[FCurrentUpdateBuffer].UpdateKind := ukModify;
|
||||||
end
|
end
|
||||||
@ -1436,7 +1468,7 @@ begin
|
|||||||
move(ActiveBuffer^,FRecordArray[FCurrentRecInd]^,FRecordSize);
|
move(ActiveBuffer^,FRecordArray[FCurrentRecInd]^,FRecordSize);
|
||||||
{$ELSE}
|
{$ELSE}
|
||||||
CurrBuff := pchar(FCurrentRecBuf);
|
CurrBuff := pchar(FCurrentRecBuf);
|
||||||
inc(Currbuff,sizeof(TBufRecLinkItem)*FIndexesCount);
|
inc(Currbuff,sizeof(TBufRecLinkItem)*FMaxIndexesCount);
|
||||||
move(ActiveBuffer^,CurrBuff^,FRecordSize);
|
move(ActiveBuffer^,CurrBuff^,FRecordSize);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
@ -1724,11 +1756,18 @@ begin
|
|||||||
InitialiseIndex(FIndexes[FIndexesCount-1]);
|
InitialiseIndex(FIndexes[FIndexesCount-1]);
|
||||||
FIndexes[FIndexesCount-1].Name:=AName;
|
FIndexes[FIndexesCount-1].Name:=AName;
|
||||||
FIndexes[FIndexesCount-1].FieldsName:=AFields;
|
FIndexes[FIndexesCount-1].FieldsName:=AFields;
|
||||||
if Active then FIndexes[FIndexesCount-1].Fields := FieldByName(AFields);
|
|
||||||
FIndexes[FIndexesCount-1].IndNr:=FIndexesCount-1;
|
FIndexes[FIndexesCount-1].IndNr:=FIndexesCount-1;
|
||||||
{$IFDEF ARRAYBUF}
|
{$IFDEF ARRAYBUF}
|
||||||
setlength(FIndexes[FIndexesCount-1].FRecordArray,FInitialBuffers);
|
setlength(FIndexes[FIndexesCount-1].FRecordArray,FInitialBuffers);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
if Active then
|
||||||
|
begin
|
||||||
|
FIndexes[FIndexesCount-1].Fields := FieldByName(AFields);
|
||||||
|
FIndexes[FIndexesCount-1].FFirstRecBuf := pointer(IntAllocRecordBuffer);
|
||||||
|
FIndexes[FIndexesCount-1].FLastRecBuf := FIndexes[FIndexesCount-1].FFirstRecBuf;
|
||||||
|
FIndexes[FIndexesCount-1].FCurrentRecBuf := FIndexes[FIndexesCount-1].FLastRecBuf;
|
||||||
|
BuildIndex(FIndexes[FIndexesCount-1]);
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TBufDataset.DoFilterRecord(var Acceptable: Boolean);
|
procedure TBufDataset.DoFilterRecord(var Acceptable: Boolean);
|
||||||
@ -1870,7 +1909,7 @@ begin
|
|||||||
FieldBufPos := FFieldBufPositions[keyfield.FieldNo-1];
|
FieldBufPos := FFieldBufPositions[keyfield.FieldNo-1];
|
||||||
VBLength := keyfield.DataSize;
|
VBLength := keyfield.DataSize;
|
||||||
ValueBuffer := AllocMem(VBLength);
|
ValueBuffer := AllocMem(VBLength);
|
||||||
currbuff := pointer(FCurrentIndex^.FLastRecBuf)+sizeof(TBufRecLinkItem)*FIndexesCount+FieldBufPos;
|
currbuff := pointer(FCurrentIndex^.FLastRecBuf)+sizeof(TBufRecLinkItem)*FMaxIndexesCount+FieldBufPos;
|
||||||
move(currbuff^,ValueBuffer^,VBLength);
|
move(currbuff^,ValueBuffer^,VBLength);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -1879,7 +1918,7 @@ begin
|
|||||||
if CheckNull then
|
if CheckNull then
|
||||||
begin
|
begin
|
||||||
repeat
|
repeat
|
||||||
currbuff := pointer(CurrLinkItem)+sizeof(TBufRecLinkItem)*FIndexesCount;
|
currbuff := pointer(CurrLinkItem)+sizeof(TBufRecLinkItem)*FMaxIndexesCount;
|
||||||
if GetFieldIsnull(pbyte(CurrBuff),keyfield.Fieldno-1) then
|
if GetFieldIsnull(pbyte(CurrBuff),keyfield.Fieldno-1) then
|
||||||
begin
|
begin
|
||||||
result := True;
|
result := True;
|
||||||
@ -1892,7 +1931,7 @@ begin
|
|||||||
else if keyfield.DataType = ftString then
|
else if keyfield.DataType = ftString then
|
||||||
begin
|
begin
|
||||||
repeat
|
repeat
|
||||||
currbuff := pointer(CurrLinkItem)+sizeof(TBufRecLinkItem)*FIndexesCount;
|
currbuff := pointer(CurrLinkItem)+sizeof(TBufRecLinkItem)*FMaxIndexesCount;
|
||||||
if not GetFieldIsnull(pbyte(CurrBuff),keyfield.Fieldno-1) then
|
if not GetFieldIsnull(pbyte(CurrBuff),keyfield.Fieldno-1) then
|
||||||
begin
|
begin
|
||||||
inc(CurrBuff,FieldBufPos);
|
inc(CurrBuff,FieldBufPos);
|
||||||
@ -1909,7 +1948,7 @@ begin
|
|||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
repeat
|
repeat
|
||||||
currbuff := pointer(CurrLinkItem)+sizeof(TBufRecLinkItem)*FIndexesCount;
|
currbuff := pointer(CurrLinkItem)+sizeof(TBufRecLinkItem)*FMaxIndexesCount;
|
||||||
if not GetFieldIsnull(pbyte(CurrBuff),keyfield.Fieldno-1) then
|
if not GetFieldIsnull(pbyte(CurrBuff),keyfield.Fieldno-1) then
|
||||||
begin
|
begin
|
||||||
inc(CurrBuff,FieldBufPos);
|
inc(CurrBuff,FieldBufPos);
|
||||||
|
Loading…
Reference in New Issue
Block a user