mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-17 04:19:07 +02:00
* Fix bug ID #32962, allowing to define multiple indexes in indexdefs
git-svn-id: trunk@38353 -
This commit is contained in:
parent
45fdd7655d
commit
10d20a57b7
File diff suppressed because it is too large
Load Diff
@ -1068,7 +1068,7 @@ type
|
|||||||
Procedure SetItem(Index: Integer; Value: TIndexDef);
|
Procedure SetItem(Index: Integer; Value: TIndexDef);
|
||||||
public
|
public
|
||||||
constructor Create(ADataSet: TDataSet); virtual; overload;
|
constructor Create(ADataSet: TDataSet); virtual; overload;
|
||||||
procedure Add(const Name, Fields: string; Options: TIndexOptions);
|
procedure Add(const Name, Fields: string; Options: TIndexOptions); overload;
|
||||||
Function AddIndexDef: TIndexDef;
|
Function AddIndexDef: TIndexDef;
|
||||||
function Find(const IndexName: string): TIndexDef;
|
function Find(const IndexName: string): TIndexDef;
|
||||||
function FindIndexForFields(const Fields: string): TIndexDef;
|
function FindIndexForFields(const Fields: string): TIndexDef;
|
||||||
@ -2474,14 +2474,19 @@ end;
|
|||||||
Function TIndexDefs.AddIndexDef: TIndexDef;
|
Function TIndexDefs.AddIndexDef: TIndexDef;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
// Result := inherited add as TIndexDef;
|
Result := inherited add as TIndexDef;
|
||||||
Result:=TIndexDef.Create(Self,'','',[]);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TIndexDefs.Add(const Name, Fields: string; Options: TIndexOptions);
|
procedure TIndexDefs.Add(const Name, Fields: string; Options: TIndexOptions);
|
||||||
|
|
||||||
|
Var
|
||||||
|
D : TIndexDef;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
TIndexDef.Create(Self,Name,Fields,Options);
|
D:=AddIndexDef;
|
||||||
|
D.Name:=Name;
|
||||||
|
D.Fields:=Fields;
|
||||||
|
D.Options:=Options;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TIndexDefs.Find(const IndexName: string): TIndexDef;
|
function TIndexDefs.Find(const IndexName: string): TIndexDef;
|
||||||
|
@ -102,7 +102,7 @@ Resourcestring
|
|||||||
SNoFieldIndexes = 'No index currently active';
|
SNoFieldIndexes = 'No index currently active';
|
||||||
SNotIndexField = 'Field ''%s'' is not indexed and cannot be modified';
|
SNotIndexField = 'Field ''%s'' is not indexed and cannot be modified';
|
||||||
SErrUnknownConnectorType = 'Unknown connector type: "%s"';
|
SErrUnknownConnectorType = 'Unknown connector type: "%s"';
|
||||||
SNoIndexFieldNameGiven = 'There are no fields selected to base the index on';
|
SNoIndexFieldNameGiven = 'Cannot create index "%s": No fields available.';
|
||||||
SStreamNotRecognised = 'The data-stream format is not recognized';
|
SStreamNotRecognised = 'The data-stream format is not recognized';
|
||||||
SNoReaderClassRegistered = 'There is no TDatapacketReaderClass registered for this kind of data-stream';
|
SNoReaderClassRegistered = 'There is no TDatapacketReaderClass registered for this kind of data-stream';
|
||||||
SErrCircularDataSourceReferenceNotAllowed = 'Circular datasource references are not allowed.';
|
SErrCircularDataSourceReferenceNotAllowed = 'Circular datasource references are not allowed.';
|
||||||
|
@ -294,6 +294,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TTestDBBasics.TestMove;
|
procedure TTestDBBasics.TestMove;
|
||||||
|
|
||||||
var i,count : integer;
|
var i,count : integer;
|
||||||
aDatasource : TDataSource;
|
aDatasource : TDataSource;
|
||||||
aDatalink : TDataLink;
|
aDatalink : TDataLink;
|
||||||
@ -1951,7 +1952,6 @@ begin
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
MaxIndexesCount := 3;
|
MaxIndexesCount := 3;
|
||||||
|
|
||||||
try
|
try
|
||||||
open;
|
open;
|
||||||
except
|
except
|
||||||
@ -1974,9 +1974,9 @@ begin
|
|||||||
while not eof do
|
while not eof do
|
||||||
begin
|
begin
|
||||||
if AFieldType=ftString then
|
if AFieldType=ftString then
|
||||||
CheckTrue(AnsiCompareStr(VarToStr(LastValue),VarToStr(FieldByName('F'+FieldTypeNames[AfieldType]).AsString))<=0)
|
CheckTrue(AnsiCompareStr(VarToStr(LastValue),VarToStr(FieldByName('F'+FieldTypeNames[AfieldType]).AsString))<=0,'Forward, Correct string value')
|
||||||
else
|
else
|
||||||
CheckTrue(LastValue<=FieldByName('F'+FieldTypeNames[AfieldType]).AsVariant);
|
CheckTrue(LastValue<=FieldByName('F'+FieldTypeNames[AfieldType]).AsVariant,'Forward, Correct variant value');
|
||||||
LastValue:=FieldByName('F'+FieldTypeNames[AfieldType]).AsVariant;
|
LastValue:=FieldByName('F'+FieldTypeNames[AfieldType]).AsVariant;
|
||||||
Next;
|
Next;
|
||||||
end;
|
end;
|
||||||
@ -1984,9 +1984,9 @@ begin
|
|||||||
while not bof do
|
while not bof do
|
||||||
begin
|
begin
|
||||||
if AFieldType=ftString then
|
if AFieldType=ftString then
|
||||||
CheckTrue(AnsiCompareStr(VarToStr(LastValue),VarToStr(FieldByName('F'+FieldTypeNames[AfieldType]).AsString))>=0)
|
CheckTrue(AnsiCompareStr(VarToStr(LastValue),VarToStr(FieldByName('F'+FieldTypeNames[AfieldType]).AsString))>=0,'Backward, Correct string value')
|
||||||
else
|
else
|
||||||
CheckTrue(LastValue>=FieldByName('F'+FieldTypeNames[AfieldType]).AsVariant);
|
CheckTrue(LastValue>=FieldByName('F'+FieldTypeNames[AfieldType]).AsVariant,'Backward, Correct variant value');
|
||||||
LastValue:=FieldByName('F'+FieldTypeNames[AfieldType]).AsVariant;
|
LastValue:=FieldByName('F'+FieldTypeNames[AfieldType]).AsVariant;
|
||||||
Prior;
|
Prior;
|
||||||
end;
|
end;
|
||||||
@ -2428,12 +2428,13 @@ begin
|
|||||||
with ds do
|
with ds do
|
||||||
begin
|
begin
|
||||||
AFieldType:=ftString;
|
AFieldType:=ftString;
|
||||||
|
|
||||||
AddIndex('testindex','F'+FieldTypeNames[AfieldType],[]);
|
AddIndex('testindex','F'+FieldTypeNames[AfieldType],[]);
|
||||||
IndexName:='testindex';
|
IndexName:='testindex';
|
||||||
open; //Record 0
|
Open;
|
||||||
OldStringValue:=FieldByName('F'+FieldTypeNames[AfieldType]).AsString;
|
OldStringValue:=FieldByName('F'+FieldTypeNames[AfieldType]).AsString;
|
||||||
next; //Now on record 1
|
next; //Now on record 1
|
||||||
CheckTrue(OldStringValue<=FieldByName('F'+FieldTypeNames[AfieldType]).AsString,'Record 0 must be smaller than record 1 with asc sorted index');
|
CheckTrue(AnsiCompareStr(OldStringValue,FieldByName('F'+FieldTypeNames[AfieldType]).AsString)<=0,'Record 0 must be smaller than record 1 with asc sorted index');
|
||||||
OldStringValue:=FieldByName('F'+FieldTypeNames[AfieldType]).AsString;
|
OldStringValue:=FieldByName('F'+FieldTypeNames[AfieldType]).AsString;
|
||||||
next; //Now on record 2
|
next; //Now on record 2
|
||||||
CheckTrue(AnsiCompareStr(OldStringValue,FieldByName('F'+FieldTypeNames[AfieldType]).AsString)<=0,'Record 1 must be smaller than record 2 with asc sorted index');
|
CheckTrue(AnsiCompareStr(OldStringValue,FieldByName('F'+FieldTypeNames[AfieldType]).AsString)<=0,'Record 1 must be smaller than record 2 with asc sorted index');
|
||||||
@ -2442,7 +2443,6 @@ begin
|
|||||||
edit;
|
edit;
|
||||||
FieldByName('F'+FieldTypeNames[AfieldType]).AsString := 'ZZZ'; //should be sorted last
|
FieldByName('F'+FieldTypeNames[AfieldType]).AsString := 'ZZZ'; //should be sorted last
|
||||||
post;
|
post;
|
||||||
|
|
||||||
prior; // Now on record 0
|
prior; // Now on record 0
|
||||||
// Check ZZZ is sorted on/after record 0
|
// Check ZZZ is sorted on/after record 0
|
||||||
CheckTrue(AnsiCompareStr('ZZZ',FieldByName('F'+FieldTypeNames[AfieldType]).AsString)>=0, 'Prior>');
|
CheckTrue(AnsiCompareStr('ZZZ',FieldByName('F'+FieldTypeNames[AfieldType]).AsString)>=0, 'Prior>');
|
||||||
@ -2469,7 +2469,6 @@ begin
|
|||||||
// empty dataset and other than default index (default_order) active
|
// empty dataset and other than default index (default_order) active
|
||||||
CheckTrue(BOF, 'No BOF when opening empty dataset');
|
CheckTrue(BOF, 'No BOF when opening empty dataset');
|
||||||
CheckTrue(EOF, 'No EOF when opening empty dataset');
|
CheckTrue(EOF, 'No EOF when opening empty dataset');
|
||||||
|
|
||||||
// append data at end
|
// append data at end
|
||||||
for i:=20 downto 0 do
|
for i:=20 downto 0 do
|
||||||
AppendRecord([i, inttostr(i)]);
|
AppendRecord([i, inttostr(i)]);
|
||||||
@ -2528,20 +2527,16 @@ begin
|
|||||||
with ds do
|
with ds do
|
||||||
begin
|
begin
|
||||||
AFieldType:=ftString;
|
AFieldType:=ftString;
|
||||||
|
|
||||||
IndexFieldNames:='F'+FieldTypeNames[AfieldType];
|
IndexFieldNames:='F'+FieldTypeNames[AfieldType];
|
||||||
|
|
||||||
open;
|
open;
|
||||||
PrevValue:='';
|
PrevValue:='';
|
||||||
while not eof do
|
while not eof do
|
||||||
begin
|
begin
|
||||||
CheckTrue(AnsiCompareStr(FieldByName('F'+FieldTypeNames[AfieldType]).AsString,PrevValue)>=0);
|
CheckTrue(AnsiCompareStr(FieldByName('F'+FieldTypeNames[AfieldType]).AsString,PrevValue)>=0,IntToStr(RecNo)+': '+FieldByName('F'+FieldTypeNames[AfieldType]).AsString+'>='+PrevValue+' ?');
|
||||||
PrevValue:=FieldByName('F'+FieldTypeNames[AfieldType]).AsString;
|
PrevValue:=FieldByName('F'+FieldTypeNames[AfieldType]).AsString;
|
||||||
Next;
|
Next;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
CheckEquals('F'+FieldTypeNames[AfieldType],IndexFieldNames);
|
CheckEquals('F'+FieldTypeNames[AfieldType],IndexFieldNames);
|
||||||
|
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -2552,7 +2547,7 @@ begin
|
|||||||
bufds := DBConnector.GetNDataset(5) as TCustomBufDataset;
|
bufds := DBConnector.GetNDataset(5) as TCustomBufDataset;
|
||||||
s := bufds.IndexFieldNames;
|
s := bufds.IndexFieldNames;
|
||||||
s := bufds.IndexName;
|
s := bufds.IndexName;
|
||||||
AssertTrue(S<>'');
|
CheckEquals('',S,'Default index name');
|
||||||
bufds.CompareBookmarks(nil,nil);
|
bufds.CompareBookmarks(nil,nil);
|
||||||
end;
|
end;
|
||||||
{$endif fpc}
|
{$endif fpc}
|
||||||
|
Loading…
Reference in New Issue
Block a user