2
0
Эх сурвалжийг харах

* Forgot to apply patch from #21905 in trunk

git-svn-id: trunk@21627 -
michael 13 жил өмнө
parent
commit
872409d293

+ 10 - 23
packages/fcl-db/src/base/dataset.inc

@@ -1822,33 +1822,20 @@ end;
 
 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
   F: TField;
-  Names,N : String;
+  N: String;
+  StrPos: Integer;
 
 begin
-  Names:=FieldNames;
-  N:=Nextname(Names);
-  while (N<>'') do
-    begin
-    F:=FieldByName(N);
-    If Assigned(List) then
-      List.Add(F);
-    N:=NextName(Names);
-    end;
+  if (FieldNames = '') or (List = nil) then
+    Exit;
+  StrPos := 1;
+  repeat
+    N := ExtractFieldName(FieldNames, StrPos);
+    F := FieldByName(N);
+    List.Add(F);
+  until StrPos > Length(FieldNames);
 end;
 
 Procedure TDataset.GetFieldNames(List: TStrings);

+ 11 - 18
packages/fcl-db/src/base/dsparams.inc

@@ -125,27 +125,20 @@ end;
 
 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
-  L,N : String;
+  P: TParam;
+  N: String;
+  StrPos: Integer;
 
 begin
-  L:=ParamNames;
-  While (Length(L)>0) do
-    begin
-    N:=NextName(L);
-    List.Add(ParamByName(N));
-    end;
+  if (ParamNames = '') or (List = nil) then
+    Exit;
+  StrPos := 1;
+  repeat
+    N := ExtractFieldName(ParamNames, StrPos);
+    P := ParamByName(N);
+    List.Add(P);
+  until StrPos > Length(ParamNames);
 end;
 
 Function TParams.IsEqual(Value: TParams): Boolean;

+ 126 - 0
packages/fcl-db/tests/testbasics.pas

@@ -22,6 +22,8 @@ type
     procedure TestInitFielddefsFromFields;
     procedure TestDoubleFieldDef;
     procedure TestFieldDefWithoutDS;
+    procedure TestGetParamList;
+    procedure TestGetFieldList;
     procedure TestExtractFieldName;
   end;
 
@@ -189,6 +191,130 @@ begin
   FieldDefs.Free;
 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;
 var