mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-11 12:46:06 +02:00
parent
7cda919547
commit
872409d293
@ -1822,33 +1822,20 @@ end;
|
|||||||
|
|
||||||
Procedure TDataset.GetFieldList(List: TList; const FieldNames: string);
|
Procedure TDataset.GetFieldList(List: TList; const FieldNames: string);
|
||||||
|
|
||||||
Function NextName(Var S : String) : String;
|
|
||||||
|
|
||||||
Var
|
|
||||||
P : integer;
|
|
||||||
|
|
||||||
begin
|
|
||||||
P:=Pos(';',S);
|
|
||||||
If (P=0) then
|
|
||||||
P:=Length(S)+1;
|
|
||||||
Result:=Copy(S,1,P-1);
|
|
||||||
system.Delete(S,1,P);
|
|
||||||
end;
|
|
||||||
|
|
||||||
var
|
var
|
||||||
F: TField;
|
F: TField;
|
||||||
Names,N : String;
|
N: String;
|
||||||
|
StrPos: Integer;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Names:=FieldNames;
|
if (FieldNames = '') or (List = nil) then
|
||||||
N:=Nextname(Names);
|
Exit;
|
||||||
while (N<>'') do
|
StrPos := 1;
|
||||||
begin
|
repeat
|
||||||
F:=FieldByName(N);
|
N := ExtractFieldName(FieldNames, StrPos);
|
||||||
If Assigned(List) then
|
F := FieldByName(N);
|
||||||
List.Add(F);
|
List.Add(F);
|
||||||
N:=NextName(Names);
|
until StrPos > Length(FieldNames);
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Procedure TDataset.GetFieldNames(List: TStrings);
|
Procedure TDataset.GetFieldNames(List: TStrings);
|
||||||
|
@ -125,27 +125,20 @@ end;
|
|||||||
|
|
||||||
Procedure TParams.GetParamList(List: TList; const ParamNames: string);
|
Procedure TParams.GetParamList(List: TList; const ParamNames: string);
|
||||||
|
|
||||||
Function NextName(Var S : String) : String;
|
|
||||||
Var
|
|
||||||
P : Integer;
|
|
||||||
begin
|
|
||||||
P:=Pos(';',S);
|
|
||||||
If (P=0) then
|
|
||||||
P:=Length(S)+1;
|
|
||||||
Result:=Copy(S,1,P-1);
|
|
||||||
system.Delete(S,1,P);
|
|
||||||
end;
|
|
||||||
|
|
||||||
Var
|
Var
|
||||||
L,N : String;
|
P: TParam;
|
||||||
|
N: String;
|
||||||
|
StrPos: Integer;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
L:=ParamNames;
|
if (ParamNames = '') or (List = nil) then
|
||||||
While (Length(L)>0) do
|
Exit;
|
||||||
begin
|
StrPos := 1;
|
||||||
N:=NextName(L);
|
repeat
|
||||||
List.Add(ParamByName(N));
|
N := ExtractFieldName(ParamNames, StrPos);
|
||||||
end;
|
P := ParamByName(N);
|
||||||
|
List.Add(P);
|
||||||
|
until StrPos > Length(ParamNames);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Function TParams.IsEqual(Value: TParams): Boolean;
|
Function TParams.IsEqual(Value: TParams): Boolean;
|
||||||
|
@ -22,6 +22,8 @@ type
|
|||||||
procedure TestInitFielddefsFromFields;
|
procedure TestInitFielddefsFromFields;
|
||||||
procedure TestDoubleFieldDef;
|
procedure TestDoubleFieldDef;
|
||||||
procedure TestFieldDefWithoutDS;
|
procedure TestFieldDefWithoutDS;
|
||||||
|
procedure TestGetParamList;
|
||||||
|
procedure TestGetFieldList;
|
||||||
procedure TestExtractFieldName;
|
procedure TestExtractFieldName;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -189,6 +191,130 @@ begin
|
|||||||
FieldDefs.Free;
|
FieldDefs.Free;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TTestBasics.TestGetFieldList;
|
||||||
|
var
|
||||||
|
ds: TDataSet;
|
||||||
|
F: TField;
|
||||||
|
List: TList;
|
||||||
|
ExceptionRaised: Boolean;
|
||||||
|
begin
|
||||||
|
ds := TDataSet.Create(nil);
|
||||||
|
try
|
||||||
|
F := TIntegerField.Create(ds);
|
||||||
|
F.FieldName := 'Field1';
|
||||||
|
F.DataSet := ds;
|
||||||
|
|
||||||
|
F := TIntegerField.Create(ds);
|
||||||
|
F.FieldName := 'Field2';
|
||||||
|
F.DataSet := ds;
|
||||||
|
|
||||||
|
F := TIntegerField.Create(ds);
|
||||||
|
F.FieldName := 'Field3';
|
||||||
|
F.DataSet := ds;
|
||||||
|
|
||||||
|
List := TList.Create;
|
||||||
|
try
|
||||||
|
//should not
|
||||||
|
List.Clear;
|
||||||
|
ds.GetFieldList(List, '');
|
||||||
|
AssertEquals(0, List.Count);
|
||||||
|
|
||||||
|
List.Clear;
|
||||||
|
ExceptionRaised := False;
|
||||||
|
try
|
||||||
|
ds.GetFieldList(List, ' ');
|
||||||
|
except
|
||||||
|
on E: EDatabaseError do ExceptionRaised := True;
|
||||||
|
end;
|
||||||
|
AssertTrue(ExceptionRaised);
|
||||||
|
|
||||||
|
List.Clear;
|
||||||
|
ds.GetFieldList(List, 'Field1');
|
||||||
|
AssertEquals(1, List.Count);
|
||||||
|
|
||||||
|
List.Clear;
|
||||||
|
ds.GetFieldList(List, ' Field1 ');
|
||||||
|
AssertEquals(1, List.Count);
|
||||||
|
|
||||||
|
List.Clear;
|
||||||
|
ds.GetFieldList(List, 'Field1;Field2');
|
||||||
|
AssertEquals(2, List.Count);
|
||||||
|
|
||||||
|
List.Clear;
|
||||||
|
ds.GetFieldList(List, 'Field1;Field2;');
|
||||||
|
AssertEquals(2, List.Count);
|
||||||
|
|
||||||
|
List.Clear;
|
||||||
|
ds.GetFieldList(List, 'Field1;Field2;Field3');
|
||||||
|
AssertEquals(3, List.Count);
|
||||||
|
finally
|
||||||
|
List.Destroy;
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
ds.Destroy;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTestBasics.TestGetParamList;
|
||||||
|
var
|
||||||
|
Params: TParams;
|
||||||
|
P: TParam;
|
||||||
|
List: TList;
|
||||||
|
ExceptionRaised: Boolean;
|
||||||
|
begin
|
||||||
|
Params := TParams.Create(nil);
|
||||||
|
try
|
||||||
|
P := TParam.Create(Params, ptInput);
|
||||||
|
P.Name := 'Param1';
|
||||||
|
|
||||||
|
P := TParam.Create(Params, ptInput);
|
||||||
|
P.Name := 'Param2';
|
||||||
|
|
||||||
|
P := TParam.Create(Params, ptInput);
|
||||||
|
P.Name := 'Param3';
|
||||||
|
|
||||||
|
List := TList.Create;
|
||||||
|
try
|
||||||
|
List.Clear;
|
||||||
|
Params.GetParamList(List, '');
|
||||||
|
AssertEquals(0, List.Count);
|
||||||
|
|
||||||
|
List.Clear;
|
||||||
|
ExceptionRaised := False;
|
||||||
|
try
|
||||||
|
Params.GetParamList(List, ' ');
|
||||||
|
except
|
||||||
|
on E: EDatabaseError do ExceptionRaised := True;
|
||||||
|
end;
|
||||||
|
AssertTrue(ExceptionRaised);
|
||||||
|
|
||||||
|
List.Clear;
|
||||||
|
Params.GetParamList(List, 'Param1');
|
||||||
|
AssertEquals(1, List.Count);
|
||||||
|
|
||||||
|
List.Clear;
|
||||||
|
Params.GetParamList(List, ' Param1 ');
|
||||||
|
AssertEquals(1, List.Count);
|
||||||
|
|
||||||
|
List.Clear;
|
||||||
|
Params.GetParamList(List, 'Param1;');
|
||||||
|
AssertEquals(1, List.Count);
|
||||||
|
|
||||||
|
List.Clear;
|
||||||
|
Params.GetParamList(List, 'Param1;Param2');
|
||||||
|
AssertEquals(2, List.Count);
|
||||||
|
|
||||||
|
List.Clear;
|
||||||
|
Params.GetParamList(List, 'Param1;Param2;Param3');
|
||||||
|
AssertEquals(3, List.Count);
|
||||||
|
finally
|
||||||
|
List.Destroy;
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
Params.Destroy;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
procedure TTestBasics.TestExtractFieldName;
|
procedure TTestBasics.TestExtractFieldName;
|
||||||
var
|
var
|
||||||
|
Loading…
Reference in New Issue
Block a user