|
@@ -19,14 +19,48 @@ type
|
|
|
procedure TestOnFilterProc(DataSet: TDataSet; var Accept: Boolean);
|
|
|
procedure TestfieldDefinition(AFieldType : TFieldType;ADatasize : integer;var ADS : TDataset; var AFld: TField);
|
|
|
procedure TestcalculatedField_OnCalcfields(DataSet: TDataSet);
|
|
|
+
|
|
|
+ procedure FTestDelete1(TestCancelUpdate : boolean);
|
|
|
+ procedure FTestDelete2(TestCancelUpdate : boolean);
|
|
|
+ procedure TestAddIndexFieldType(AFieldType : TFieldType; ActiveDS : boolean);
|
|
|
protected
|
|
|
procedure SetUp; override;
|
|
|
procedure TearDown; override;
|
|
|
published
|
|
|
+ procedure TestCancelUpdDelete1;
|
|
|
+ procedure TestCancelUpdDelete2;
|
|
|
+ procedure TestBookmarks;
|
|
|
+
|
|
|
+ procedure TestFirst;
|
|
|
+ procedure TestDelete1;
|
|
|
+ procedure TestDelete2;
|
|
|
procedure TestIntFilter;
|
|
|
procedure TestOnFilter;
|
|
|
procedure TestStringFilter;
|
|
|
|
|
|
+ procedure TestAddIndex;
|
|
|
+ procedure TestInactSwitchIndex;
|
|
|
+
|
|
|
+ procedure TestAddIndexInteger;
|
|
|
+ procedure TestAddIndexSmallInt;
|
|
|
+ procedure TestAddIndexBoolean;
|
|
|
+ procedure TestAddIndexFloat;
|
|
|
+ procedure TestAddIndexLargeInt;
|
|
|
+ procedure TestAddIndexDateTime;
|
|
|
+ procedure TestAddIndexCurrency;
|
|
|
+ procedure TestAddIndexBCD;
|
|
|
+
|
|
|
+ procedure TestAddIndexActiveDS;
|
|
|
+ procedure TestAddIndexEditDS;
|
|
|
+
|
|
|
+ procedure TestIndexFieldNames;
|
|
|
+ procedure TestIndexFieldNamesAct;
|
|
|
+
|
|
|
+ procedure TestIndexCurRecord;
|
|
|
+
|
|
|
+ procedure TestAddDblIndex;
|
|
|
+ procedure TestIndexEditRecord;
|
|
|
+
|
|
|
procedure TestNullAtOpen;
|
|
|
|
|
|
procedure TestSupportIntegerFields;
|
|
@@ -453,6 +487,237 @@ begin
|
|
|
DBConnector.StopTest;
|
|
|
end;
|
|
|
|
|
|
+procedure TTestDBBasics.TestBookmarks;
|
|
|
+var BM1,BM2,BM3,BM4,BM5 : TBookmark;
|
|
|
+begin
|
|
|
+ with DBConnector.GetNDataset(true,14) do
|
|
|
+ begin
|
|
|
+ AssertNull(GetBookmark);
|
|
|
+ open;
|
|
|
+ BM1:=GetBookmark; // id=1, BOF
|
|
|
+ next;next;
|
|
|
+ BM2:=GetBookmark; // id=3
|
|
|
+ next;next;next;
|
|
|
+ BM3:=GetBookmark; // id=6
|
|
|
+ next;next;next;next;next;next;next;next;
|
|
|
+ BM4:=GetBookmark; // id=14
|
|
|
+ next;
|
|
|
+ BM5:=GetBookmark; // id=14, EOF
|
|
|
+
|
|
|
+ GotoBookmark(BM2);
|
|
|
+ AssertEquals(3,FieldByName('id').AsInteger);
|
|
|
+
|
|
|
+ GotoBookmark(BM1);
|
|
|
+ AssertEquals(1,FieldByName('id').AsInteger);
|
|
|
+
|
|
|
+ GotoBookmark(BM3);
|
|
|
+ AssertEquals(6,FieldByName('id').AsInteger);
|
|
|
+
|
|
|
+ GotoBookmark(BM4);
|
|
|
+ AssertEquals(14,FieldByName('id').AsInteger);
|
|
|
+
|
|
|
+ GotoBookmark(BM3);
|
|
|
+ AssertEquals(6,FieldByName('id').AsInteger);
|
|
|
+
|
|
|
+ GotoBookmark(BM5);
|
|
|
+ AssertEquals(14,FieldByName('id').AsInteger);
|
|
|
+
|
|
|
+ GotoBookmark(BM1);
|
|
|
+ AssertEquals(1,FieldByName('id').AsInteger);
|
|
|
+
|
|
|
+ next;
|
|
|
+ delete;
|
|
|
+
|
|
|
+ GotoBookmark(BM2);
|
|
|
+ AssertEquals(3,FieldByName('id').AsInteger);
|
|
|
+
|
|
|
+ delete;delete;
|
|
|
+
|
|
|
+ GotoBookmark(BM3);
|
|
|
+ AssertEquals(6,FieldByName('id').AsInteger);
|
|
|
+
|
|
|
+ GotoBookmark(BM1);
|
|
|
+ AssertEquals(1,FieldByName('id').AsInteger);
|
|
|
+ insert;
|
|
|
+ fieldbyname('id').AsInteger:=20;
|
|
|
+ insert;
|
|
|
+ fieldbyname('id').AsInteger:=21;
|
|
|
+ insert;
|
|
|
+ fieldbyname('id').AsInteger:=22;
|
|
|
+ insert;
|
|
|
+ fieldbyname('id').AsInteger:=23;
|
|
|
+ post;
|
|
|
+
|
|
|
+ GotoBookmark(BM3);
|
|
|
+ AssertEquals(6,FieldByName('id').AsInteger);
|
|
|
+
|
|
|
+ GotoBookmark(BM1);
|
|
|
+ AssertEquals(1,FieldByName('id').AsInteger);
|
|
|
+
|
|
|
+ GotoBookmark(BM5);
|
|
|
+ AssertEquals(14,FieldByName('id').AsInteger);
|
|
|
+ end;
|
|
|
+end;
|
|
|
+
|
|
|
+procedure TTestDBBasics.TestFirst;
|
|
|
+var i : integer;
|
|
|
+begin
|
|
|
+ with DBConnector.GetNDataset(true,14) do
|
|
|
+ begin
|
|
|
+ open;
|
|
|
+ AssertEquals(1,FieldByName('ID').AsInteger);
|
|
|
+ First;
|
|
|
+ AssertEquals(1,FieldByName('ID').AsInteger);
|
|
|
+ next;
|
|
|
+ AssertEquals(2,FieldByName('ID').AsInteger);
|
|
|
+ First;
|
|
|
+ AssertEquals(1,FieldByName('ID').AsInteger);
|
|
|
+ for i := 0 to 12 do
|
|
|
+ next;
|
|
|
+ AssertEquals(14,FieldByName('ID').AsInteger);
|
|
|
+ First;
|
|
|
+ AssertEquals(1,FieldByName('ID').AsInteger);
|
|
|
+ close;
|
|
|
+ end;
|
|
|
+end;
|
|
|
+
|
|
|
+procedure TTestDBBasics.TestDelete1;
|
|
|
+begin
|
|
|
+ FTestDelete1(false);
|
|
|
+end;
|
|
|
+
|
|
|
+procedure TTestDBBasics.TestDelete2;
|
|
|
+begin
|
|
|
+ FTestDelete2(false);
|
|
|
+end;
|
|
|
+
|
|
|
+procedure TTestDBBasics.TestCancelUpdDelete1;
|
|
|
+begin
|
|
|
+ FTestDelete1(true);
|
|
|
+end;
|
|
|
+
|
|
|
+procedure TTestDBBasics.TestCancelUpdDelete2;
|
|
|
+begin
|
|
|
+ FTestDelete2(true);
|
|
|
+end;
|
|
|
+
|
|
|
+procedure TTestDBBasics.FTestDelete1(TestCancelUpdate : boolean);
|
|
|
+// Test the deletion of records, including the first and the last one
|
|
|
+var i : integer;
|
|
|
+ ds : TDataset;
|
|
|
+begin
|
|
|
+ ds := DBConnector.GetNDataset(true,17);
|
|
|
+ with ds do
|
|
|
+ begin
|
|
|
+ Open;
|
|
|
+
|
|
|
+ for i := 0 to 16 do if i mod 4=0 then
|
|
|
+ delete
|
|
|
+ else
|
|
|
+ next;
|
|
|
+
|
|
|
+ First;
|
|
|
+ for i := 0 to 16 do
|
|
|
+ begin
|
|
|
+ if i mod 4<>0 then
|
|
|
+ begin
|
|
|
+ AssertEquals(i+1,FieldByName('ID').AsInteger);
|
|
|
+ AssertEquals('TestName'+inttostr(i+1),FieldByName('NAME').AsString);
|
|
|
+ next;
|
|
|
+ end;
|
|
|
+ end;
|
|
|
+ end;
|
|
|
+
|
|
|
+ if TestCancelUpdate then
|
|
|
+ begin
|
|
|
+ if not (ds is TBufDataset) then
|
|
|
+ Ignore('This test only applies to TBufDataset and descendents.');
|
|
|
+ with TBufDataset(ds) do
|
|
|
+ begin
|
|
|
+ CancelUpdates;
|
|
|
+
|
|
|
+ First;
|
|
|
+ for i := 0 to 16 do
|
|
|
+ begin
|
|
|
+ AssertEquals(i+1,FieldByName('ID').AsInteger);
|
|
|
+ AssertEquals('TestName'+inttostr(i+1),FieldByName('NAME').AsString);
|
|
|
+ next;
|
|
|
+ end;
|
|
|
+
|
|
|
+ close;
|
|
|
+ end;
|
|
|
+ end;
|
|
|
+end;
|
|
|
+
|
|
|
+procedure TTestDBBasics.FTestDelete2(TestCancelUpdate : boolean);
|
|
|
+// Test the deletion of edited and appended records
|
|
|
+var i : integer;
|
|
|
+ ds : TDataset;
|
|
|
+begin
|
|
|
+ ds := DBConnector.GetNDataset(true,17);
|
|
|
+ with ds do
|
|
|
+ begin
|
|
|
+ Open;
|
|
|
+
|
|
|
+ for i := 0 to 16 do
|
|
|
+ begin
|
|
|
+ if i mod 4=0 then
|
|
|
+ begin
|
|
|
+ edit;
|
|
|
+ fieldbyname('name').AsString:='this record will be gone soon';
|
|
|
+ post;
|
|
|
+ end;
|
|
|
+ next;
|
|
|
+ end;
|
|
|
+
|
|
|
+ for i := 17 to 20 do
|
|
|
+ begin
|
|
|
+ append;
|
|
|
+ fieldbyname('id').AsInteger:=i+1;
|
|
|
+ fieldbyname('name').AsString:='TestName'+inttostr(i+1);
|
|
|
+ post;
|
|
|
+ end;
|
|
|
+
|
|
|
+ first;
|
|
|
+ for i := 0 to 20 do if i mod 4=0 then
|
|
|
+ delete
|
|
|
+ else
|
|
|
+ next;
|
|
|
+
|
|
|
+ First;
|
|
|
+ i := 0;
|
|
|
+ for i := 0 to 20 do
|
|
|
+ begin
|
|
|
+ if i mod 4<>0 then
|
|
|
+ begin
|
|
|
+ AssertEquals(i+1,FieldByName('ID').AsInteger);
|
|
|
+ AssertEquals('TestName'+inttostr(i+1),FieldByName('NAME').AsString);
|
|
|
+ next;
|
|
|
+ end;
|
|
|
+ end;
|
|
|
+ end;
|
|
|
+
|
|
|
+ if TestCancelUpdate then
|
|
|
+ begin
|
|
|
+ if not (ds is TBufDataset) then
|
|
|
+ Ignore('This test only applies to TBufDataset and descendents.');
|
|
|
+ with TBufDataset(ds) do
|
|
|
+ begin
|
|
|
+ CancelUpdates;
|
|
|
+
|
|
|
+ First;
|
|
|
+ for i := 0 to 16 do
|
|
|
+ begin
|
|
|
+ AssertEquals(i+1,FieldByName('ID').AsInteger);
|
|
|
+ AssertEquals('TestName'+inttostr(i+1),FieldByName('NAME').AsString);
|
|
|
+ next;
|
|
|
+ end;
|
|
|
+
|
|
|
+ close;
|
|
|
+ end;
|
|
|
+ end;
|
|
|
+end;
|
|
|
+
|
|
|
procedure TTestDBBasics.TestOnFilterProc(DataSet: TDataSet; var Accept: Boolean);
|
|
|
|
|
|
var a : TDataSetState;
|
|
@@ -540,6 +805,439 @@ begin
|
|
|
end;
|
|
|
end;
|
|
|
|
|
|
+procedure TTestDBBasics.TestAddIndexFieldType(AFieldType: TFieldType; ActiveDS : boolean);
|
|
|
+var ds : TBufDataset;
|
|
|
+ FList : TStringList;
|
|
|
+ LastValue : Variant;
|
|
|
+begin
|
|
|
+ ds := DBConnector.GetFieldDataset as TBufDataset;
|
|
|
+ with ds do
|
|
|
+ begin
|
|
|
+
|
|
|
+ if not ActiveDS then
|
|
|
+ begin
|
|
|
+ AddIndex('testindex','F'+FieldTypeNames[AfieldType]);
|
|
|
+ IndexName:='testindex';
|
|
|
+ end
|
|
|
+ else
|
|
|
+ MaxIndexesCount := 3;
|
|
|
+
|
|
|
+ try
|
|
|
+ open;
|
|
|
+ except
|
|
|
+ if not assigned(ds.FindField('F'+FieldTypeNames[AfieldType])) then
|
|
|
+ Ignore('Fields of the type ' + FieldTypeNames[AfieldType] + ' are not supported by this type of dataset')
|
|
|
+ else
|
|
|
+ raise;
|
|
|
+ end;
|
|
|
+
|
|
|
+ if ActiveDS then
|
|
|
+ begin
|
|
|
+ if not assigned(ds.FindField('F'+FieldTypeNames[AfieldType])) then
|
|
|
+ Ignore('Fields of the type ' + FieldTypeNames[AfieldType] + ' are not supported by this type of dataset');
|
|
|
+ AddIndex('testindex','F'+FieldTypeNames[AfieldType]);
|
|
|
+ IndexName:='testindex';
|
|
|
+ First;
|
|
|
+ end;
|
|
|
+
|
|
|
+ LastValue:=null;
|
|
|
+ while not eof do
|
|
|
+ begin
|
|
|
+ AssertTrue(LastValue<=FieldByName('F'+FieldTypeNames[AfieldType]).AsVariant);
|
|
|
+ LastValue:=FieldByName('F'+FieldTypeNames[AfieldType]).AsVariant;
|
|
|
+ Next;
|
|
|
+ end;
|
|
|
+
|
|
|
+ while not bof do
|
|
|
+ begin
|
|
|
+ AssertTrue(LastValue>=FieldByName('F'+FieldTypeNames[AfieldType]).AsVariant);
|
|
|
+ LastValue:=FieldByName('F'+FieldTypeNames[AfieldType]).AsVariant;
|
|
|
+ Prior;
|
|
|
+ end;
|
|
|
+ end;
|
|
|
+end;
|
|
|
+
|
|
|
+procedure TTestDBBasics.TestAddIndexSmallInt;
|
|
|
+begin
|
|
|
+ TestAddIndexFieldType(ftSmallint,False);
|
|
|
+end;
|
|
|
+
|
|
|
+procedure TTestDBBasics.TestAddIndexBoolean;
|
|
|
+begin
|
|
|
+ TestAddIndexFieldType(ftBoolean,False);
|
|
|
+end;
|
|
|
+
|
|
|
+procedure TTestDBBasics.TestAddIndexFloat;
|
|
|
+begin
|
|
|
+ TestAddIndexFieldType(ftFloat,False);
|
|
|
+end;
|
|
|
+
|
|
|
+procedure TTestDBBasics.TestAddIndexInteger;
|
|
|
+begin
|
|
|
+ TestAddIndexFieldType(ftInteger,False);
|
|
|
+end;
|
|
|
+
|
|
|
+procedure TTestDBBasics.TestAddIndexLargeInt;
|
|
|
+begin
|
|
|
+ TestAddIndexFieldType(ftLargeint,False);
|
|
|
+end;
|
|
|
+
|
|
|
+procedure TTestDBBasics.TestAddIndexDateTime;
|
|
|
+begin
|
|
|
+ TestAddIndexFieldType(ftDateTime,False);
|
|
|
+end;
|
|
|
+
|
|
|
+procedure TTestDBBasics.TestAddIndexCurrency;
|
|
|
+begin
|
|
|
+ TestAddIndexFieldType(ftCurrency,False);
|
|
|
+end;
|
|
|
+
|
|
|
+procedure TTestDBBasics.TestAddIndexBCD;
|
|
|
+begin
|
|
|
+ TestAddIndexFieldType(ftBCD,False);
|
|
|
+end;
|
|
|
+
|
|
|
+procedure TTestDBBasics.TestAddIndex;
|
|
|
+var ds : TBufDataset;
|
|
|
+ AFieldType : TFieldType;
|
|
|
+ FList : TStringList;
|
|
|
+ i : integer;
|
|
|
+begin
|
|
|
+ ds := DBConnector.GetFieldDataset as TBufDataset;
|
|
|
+ with ds do
|
|
|
+ begin
|
|
|
+
|
|
|
+ AFieldType:=ftString;
|
|
|
+ AddIndex('testindex','F'+FieldTypeNames[AfieldType]);
|
|
|
+ FList := TStringList.Create;
|
|
|
+ FList.Sorted:=true;
|
|
|
+ FList.CaseSensitive:=True;
|
|
|
+ FList.Duplicates:=dupAccept;
|
|
|
+ open;
|
|
|
+
|
|
|
+ while not eof do
|
|
|
+ begin
|
|
|
+ flist.Add(FieldByName('F'+FieldTypeNames[AfieldType]).AsString);
|
|
|
+ Next;
|
|
|
+ end;
|
|
|
+
|
|
|
+ IndexName:='testindex';
|
|
|
+ first;
|
|
|
+ i:=0;
|
|
|
+
|
|
|
+ while not eof do
|
|
|
+ begin
|
|
|
+ AssertEquals(flist[i],FieldByName('F'+FieldTypeNames[AfieldType]).AsString);
|
|
|
+ inc(i);
|
|
|
+ Next;
|
|
|
+ end;
|
|
|
+
|
|
|
+ while not bof do
|
|
|
+ begin
|
|
|
+ dec(i);
|
|
|
+ AssertEquals(flist[i],FieldByName('F'+FieldTypeNames[AfieldType]).AsString);
|
|
|
+ Prior;
|
|
|
+ end;
|
|
|
+ end;
|
|
|
+end;
|
|
|
+
|
|
|
+procedure TTestDBBasics.TestInactSwitchIndex;
|
|
|
+// Test if the default-index is properly build when the active index is not
|
|
|
+// the default-index while opening then dataset
|
|
|
+var ds : TBufDataset;
|
|
|
+ AFieldType : TFieldType;
|
|
|
+ i : integer;
|
|
|
+begin
|
|
|
+ ds := DBConnector.GetFieldDataset as TBufDataset;
|
|
|
+ with ds do
|
|
|
+ begin
|
|
|
+
|
|
|
+ AFieldType:=ftString;
|
|
|
+ AddIndex('testindex','F'+FieldTypeNames[AfieldType]);
|
|
|
+ IndexName:='testindex';
|
|
|
+ open;
|
|
|
+ IndexName:=''; // This should set the default index (default_order)
|
|
|
+ first;
|
|
|
+
|
|
|
+ i := 0;
|
|
|
+
|
|
|
+ while not eof do
|
|
|
+ begin
|
|
|
+ AssertEquals(testStringValues[i],FieldByName('F'+FieldTypeNames[AfieldType]).AsString);
|
|
|
+ inc(i);
|
|
|
+ Next;
|
|
|
+ end;
|
|
|
+ end;
|
|
|
+end;
|
|
|
+
|
|
|
+procedure TTestDBBasics.TestAddIndexActiveDS;
|
|
|
+var ds : TBufDataset;
|
|
|
+ I : integer;
|
|
|
+begin
|
|
|
+ TestAddIndexFieldType(ftString,true);
|
|
|
+end;
|
|
|
+
|
|
|
+procedure TTestDBBasics.TestAddIndexEditDS;
|
|
|
+var ds : TBufDataset;
|
|
|
+ I : integer;
|
|
|
+ LastValue : String;
|
|
|
+begin
|
|
|
+ ds := DBConnector.GetNDataset(True,5) as TBufDataset;
|
|
|
+ with ds do
|
|
|
+ begin
|
|
|
+ MaxIndexesCount:=3;
|
|
|
+ open;
|
|
|
+ edit;
|
|
|
+ FieldByName('name').asstring := 'Zz';
|
|
|
+ post;
|
|
|
+ next;
|
|
|
+ next;
|
|
|
+ edit;
|
|
|
+ FieldByName('name').asstring := 'aA';
|
|
|
+ post;
|
|
|
+
|
|
|
+ AddIndex('test','name');
|
|
|
+
|
|
|
+ first;
|
|
|
+ ds.IndexName:='test';
|
|
|
+ first;
|
|
|
+ LastValue:=FieldByName('name').AsString;
|
|
|
+ while not eof do
|
|
|
+ begin
|
|
|
+ AssertTrue(LastValue<=FieldByName('name').AsString);
|
|
|
+ Next;
|
|
|
+ end;
|
|
|
+ end;
|
|
|
+end;
|
|
|
+
|
|
|
+procedure TTestDBBasics.TestIndexFieldNamesAct;
|
|
|
+var ds : TBufDataset;
|
|
|
+ AFieldType : TFieldType;
|
|
|
+ FList : TStringList;
|
|
|
+ i : integer;
|
|
|
+begin
|
|
|
+ ds := DBConnector.GetFieldDataset as TBufDataset;
|
|
|
+ with ds do
|
|
|
+ begin
|
|
|
+ AFieldType:=ftString;
|
|
|
+ FList := TStringList.Create;
|
|
|
+ FList.Sorted:=true;
|
|
|
+ FList.CaseSensitive:=True;
|
|
|
+ FList.Duplicates:=dupAccept;
|
|
|
+ open;
|
|
|
+
|
|
|
+ while not eof do
|
|
|
+ begin
|
|
|
+ flist.Add(FieldByName('F'+FieldTypeNames[AfieldType]).AsString);
|
|
|
+ Next;
|
|
|
+ end;
|
|
|
+
|
|
|
+ IndexFieldNames:='F'+FieldTypeNames[AfieldType];
|
|
|
+ first;
|
|
|
+ i:=0;
|
|
|
+
|
|
|
+ while not eof do
|
|
|
+ begin
|
|
|
+ AssertEquals(flist[i],FieldByName('F'+FieldTypeNames[AfieldType]).AsString);
|
|
|
+ inc(i);
|
|
|
+ Next;
|
|
|
+ end;
|
|
|
+
|
|
|
+ while not bof do
|
|
|
+ begin
|
|
|
+ dec(i);
|
|
|
+ AssertEquals(flist[i],FieldByName('F'+FieldTypeNames[AfieldType]).AsString);
|
|
|
+ Prior;
|
|
|
+ end;
|
|
|
+
|
|
|
+ AssertEquals('F'+FieldTypeNames[AfieldType],IndexFieldNames);
|
|
|
+
|
|
|
+ IndexFieldNames:='ID';
|
|
|
+ first;
|
|
|
+ i:=0;
|
|
|
+
|
|
|
+ while not eof do
|
|
|
+ begin
|
|
|
+ AssertEquals(testStringValues[i],FieldByName('F'+FieldTypeNames[AfieldType]).AsString);
|
|
|
+ inc(i);
|
|
|
+ Next;
|
|
|
+ end;
|
|
|
+
|
|
|
+ AssertEquals('ID',IndexFieldNames);
|
|
|
+
|
|
|
+ IndexFieldNames:='';
|
|
|
+ first;
|
|
|
+ i:=0;
|
|
|
+
|
|
|
+ while not eof do
|
|
|
+ begin
|
|
|
+ AssertEquals(testStringValues[i],FieldByName('F'+FieldTypeNames[AfieldType]).AsString);
|
|
|
+ inc(i);
|
|
|
+ Next;
|
|
|
+ end;
|
|
|
+
|
|
|
+ AssertEquals('',IndexFieldNames);
|
|
|
+
|
|
|
+ end;
|
|
|
+end;
|
|
|
+
|
|
|
+procedure TTestDBBasics.TestIndexCurRecord;
|
|
|
+// Test if the currentrecord stays the same after an index change
|
|
|
+var ds : TBufDataset;
|
|
|
+ AFieldType : TFieldType;
|
|
|
+ i : integer;
|
|
|
+ OldID : Integer;
|
|
|
+ OldStringValue : string;
|
|
|
+begin
|
|
|
+ ds := DBConnector.GetFieldDataset as TBufDataset;
|
|
|
+ with ds do
|
|
|
+ begin
|
|
|
+ AFieldType:=ftString;
|
|
|
+ AddIndex('testindex','F'+FieldTypeNames[AfieldType]);
|
|
|
+ open;
|
|
|
+
|
|
|
+ for i := 0 to (testValuesCount div 3) do
|
|
|
+ Next;
|
|
|
+
|
|
|
+ OldID:=FieldByName('id').AsInteger;
|
|
|
+ OldStringValue:=FieldByName('F'+FieldTypeNames[AfieldType]).AsString;
|
|
|
+
|
|
|
+ IndexName:='testindex';
|
|
|
+
|
|
|
+ AssertEquals(OldID,FieldByName('id').AsInteger);
|
|
|
+ AssertEquals(OldStringValue,FieldByName('F'+FieldTypeNames[AfieldType]).AsString);
|
|
|
+
|
|
|
+ next;
|
|
|
+ AssertTrue(OldStringValue<=FieldByName('F'+FieldTypeNames[AfieldType]).AsString);
|
|
|
+ prior;
|
|
|
+ prior;
|
|
|
+ AssertTrue(OldStringValue>=FieldByName('F'+FieldTypeNames[AfieldType]).AsString);
|
|
|
+
|
|
|
+ OldID:=FieldByName('id').AsInteger;
|
|
|
+ OldStringValue:=FieldByName('F'+FieldTypeNames[AfieldType]).AsString;
|
|
|
+
|
|
|
+ IndexName:='';
|
|
|
+
|
|
|
+ AssertEquals(OldID,FieldByName('id').AsInteger);
|
|
|
+ AssertEquals(OldStringValue,FieldByName('F'+FieldTypeNames[AfieldType]).AsString);
|
|
|
+
|
|
|
+ next;
|
|
|
+ AssertEquals(OldID+1,FieldByName('ID').AsInteger);
|
|
|
+ prior;
|
|
|
+ prior;
|
|
|
+ AssertEquals(OldID-1,FieldByName('ID').AsInteger);
|
|
|
+ end;
|
|
|
+end;
|
|
|
+
|
|
|
+procedure TTestDBBasics.TestAddDblIndex;
|
|
|
+var ds : TBufDataset;
|
|
|
+ FList : TStringList;
|
|
|
+ i : integer;
|
|
|
+begin
|
|
|
+ ds := DBConnector.GetFieldDataset as TBufDataset;
|
|
|
+ with ds do
|
|
|
+ begin
|
|
|
+
|
|
|
+ AddIndex('testindex','F'+FieldTypeNames[ftString]+', F'+FieldTypeNames[ftInteger]);
|
|
|
+ FList := TStringList.Create;
|
|
|
+ FList.Sorted:=true;
|
|
|
+ FList.CaseSensitive:=True;
|
|
|
+ FList.Duplicates:=dupAccept;
|
|
|
+ open;
|
|
|
+
|
|
|
+ while not eof do
|
|
|
+ begin
|
|
|
+ // If the first field of the index is null then the compound string in
|
|
|
+ // FList isn't sorted right...
|
|
|
+ if FieldByName('F'+FieldTypeNames[ftString]).IsNull then
|
|
|
+ flist.Add(' -'+ Format('%.12d',[FieldByName('F'+FieldTypeNames[ftInteger]).AsInteger]))
|
|
|
+ else
|
|
|
+ flist.Add(FieldByName('F'+FieldTypeNames[ftString]).AsString+'-'+ Format('%.12d',[FieldByName('F'+FieldTypeNames[ftInteger]).AsInteger]));
|
|
|
+ Next;
|
|
|
+ end;
|
|
|
+
|
|
|
+ IndexName:='testindex';
|
|
|
+ first;
|
|
|
+ i:=0;
|
|
|
+
|
|
|
+ while not eof do
|
|
|
+ begin
|
|
|
+ if (not FieldByName('F'+FieldTypeNames[ftString]).IsNull) then
|
|
|
+ AssertEquals(flist[i],FieldByName('F'+FieldTypeNames[ftString]).AsString+'-'+ Format('%.12d',[FieldByName('F'+FieldTypeNames[ftInteger]).AsInteger]));
|
|
|
+ inc(i);
|
|
|
+ Next;
|
|
|
+ end;
|
|
|
+ while not bof do
|
|
|
+ begin
|
|
|
+ dec(i);
|
|
|
+ if not FieldByName('F'+FieldTypeNames[ftString]).IsNull then
|
|
|
+ AssertEquals(flist[i],FieldByName('F'+FieldTypeNames[ftString]).AsString+'-'+ Format('%.12d',[FieldByName('F'+FieldTypeNames[ftInteger]).AsInteger]));
|
|
|
+ Prior;
|
|
|
+ end;
|
|
|
+ end;
|
|
|
+end;
|
|
|
+
|
|
|
+procedure TTestDBBasics.TestIndexEditRecord;
|
|
|
+var ds : TBufDataset;
|
|
|
+ AFieldType : TFieldType;
|
|
|
+ i : integer;
|
|
|
+ OldID : Integer;
|
|
|
+ OldStringValue : string;
|
|
|
+begin
|
|
|
+ ds := DBConnector.GetFieldDataset as TBufDataset;
|
|
|
+ with ds do
|
|
|
+ begin
|
|
|
+ AFieldType:=ftString;
|
|
|
+ AddIndex('testindex','F'+FieldTypeNames[AfieldType]);
|
|
|
+ IndexName:='testindex';
|
|
|
+ open;
|
|
|
+ OldStringValue:=FieldByName('F'+FieldTypeNames[AfieldType]).AsString;
|
|
|
+ next;
|
|
|
+ AssertTrue(OldStringValue<=FieldByName('F'+FieldTypeNames[AfieldType]).AsString);
|
|
|
+ OldStringValue:=FieldByName('F'+FieldTypeNames[AfieldType]).AsString;
|
|
|
+ next;
|
|
|
+ AssertTrue(OldStringValue<=FieldByName('F'+FieldTypeNames[AfieldType]).AsString);
|
|
|
+ prior;
|
|
|
+
|
|
|
+ edit;
|
|
|
+ FieldByName('F'+FieldTypeNames[AfieldType]).AsString := 'ZZZ';
|
|
|
+ post;
|
|
|
+ prior;
|
|
|
+ AssertTrue('ZZZ'>=FieldByName('F'+FieldTypeNames[AfieldType]).AsString);
|
|
|
+ next;
|
|
|
+ next;
|
|
|
+ AssertTrue('ZZZ'<=FieldByName('F'+FieldTypeNames[AfieldType]).AsString);
|
|
|
+ close;
|
|
|
+ end;
|
|
|
+end;
|
|
|
+
|
|
|
+procedure TTestDBBasics.TestIndexFieldNames;
|
|
|
+var ds : TBufDataset;
|
|
|
+ AFieldType : TFieldType;
|
|
|
+ PrevValue : String;
|
|
|
+begin
|
|
|
+ ds := DBConnector.GetFieldDataset as TBufDataset;
|
|
|
+ with ds do
|
|
|
+ begin
|
|
|
+ AFieldType:=ftString;
|
|
|
+
|
|
|
+ IndexFieldNames:='F'+FieldTypeNames[AfieldType];
|
|
|
+
|
|
|
+ open;
|
|
|
+ PrevValue:='';
|
|
|
+ while not eof do
|
|
|
+ begin
|
|
|
+ AssertTrue(FieldByName('F'+FieldTypeNames[AfieldType]).AsString>=PrevValue);
|
|
|
+ PrevValue:=FieldByName('F'+FieldTypeNames[AfieldType]).AsString;
|
|
|
+ Next;
|
|
|
+ end;
|
|
|
+
|
|
|
+ AssertEquals('F'+FieldTypeNames[AfieldType],IndexFieldNames);
|
|
|
+
|
|
|
+ end;
|
|
|
+end;
|
|
|
+
|
|
|
+
|
|
|
procedure TTestDBBasics.TestcalculatedField_OnCalcfields(DataSet: TDataSet);
|
|
|
begin
|
|
|
case dataset.fieldbyname('ID').asinteger of
|