Browse Source

* fix decimalseparator locale issues in fcl-db testsuite, mantis #19564

git-svn-id: trunk@18051 -
marco 14 years ago
parent
commit
064ecf3d6c

+ 1 - 1
packages/fcl-db/tests/sqldbtoolsunit.pas

@@ -275,7 +275,7 @@ begin
           begin
           sql := sql + ',F' + Fieldtypenames[FType];
           if testValues[FType,CountID] <> '' then
-            sql1 := sql1 + ',''' + StringReplace(testValues[FType,CountID],'''','''''',[rfReplaceAll]) + ''''
+            sql1 := sql1 + ',' + QuotedStr(testValues[FType,CountID])
           else
             sql1 := sql1 + ',NULL';
           end;

+ 2 - 3
packages/fcl-db/tests/testdbbasics.pas

@@ -1992,9 +1992,8 @@ begin
 
   for i := 0 to testValuesCount-1 do
     begin
-    AssertEquals(testFmtBCDValues[i],Fld.AsString);
-    AssertEquals(testFmtBCDValues[i],Fld.AsBCD);
-    AssertEquals(StrToFloat(testFmtBCDValues[i]),Fld.AsFloat);
+    AssertEquals(testFmtBCDValues[i], BCDToStr(Fld.AsBCD,DBConnector.FormatSettings));
+    AssertEquals(StrToFloat(testFmtBCDValues[i],DBConnector.FormatSettings), Fld.AsFloat);
     ds.Next;
     end;
   ds.close;

+ 6 - 5
packages/fcl-db/tests/testfieldtypes.pas

@@ -274,7 +274,7 @@ begin
   TestFieldDeclaration(ftBCD,sizeof(Currency));
 
   for i := 0 to testValuesCount-1 do
-    TSQLDBConnector(DBConnector).Connection.ExecuteDirect('insert into FPDEV2 (FT) values (' + CurrToStrF(testValues[i],ffFixed,3) + ')');
+    TSQLDBConnector(DBConnector).Connection.ExecuteDirect('insert into FPDEV2 (FT) values (' + CurrToStrF(testValues[i],ffFixed,3,DBConnector.FormatSettings) + ')');
 
   with TSQLDBConnector(DBConnector).Query do
     begin
@@ -614,7 +614,7 @@ begin
   TestFieldDeclaration(ftFloat,sizeof(double));
 
   for i := 0 to testValuesCount-1 do
-    TSQLDBConnector(DBConnector).Connection.ExecuteDirect('insert into FPDEV2 (FT) values (' + floattostr(testValues[i]) + ')');
+    TSQLDBConnector(DBConnector).Connection.ExecuteDirect('insert into FPDEV2 (FT) values (' + floattostr(testValues[i],DBConnector.FormatSettings) + ')');
 
   with TSQLDBConnector(DBConnector).Query do
     begin
@@ -803,7 +803,7 @@ begin
                      Params.ParamByName('field1').AsString:= testDateValues[i]
                    else
                      Params.ParamByName('field1').AsDateTime:= StrToDate(testDateValues[i],'yyyy/mm/dd','-');
-        ftFMTBcd : Params.ParamByName('field1').AsFMTBCD:= StrToBCD(testFmtBCDValues[i]{,DBConnector.FormatSettings})
+        ftFMTBcd : Params.ParamByName('field1').AsFMTBCD:= StrToBCD(testFmtBCDValues[i],DBConnector.FormatSettings)
       else
         AssertTrue('no test for paramtype available',False);
       end;
@@ -826,7 +826,7 @@ begin
         ftString : AssertEquals(testStringValues[i],FieldByName('FIELD1').AsString);
         ftTime   : AssertEquals(testTimeValues[i],DateTimeToTimeString(FieldByName('FIELD1').AsDateTime));
         ftdate   : AssertEquals(testDateValues[i],FormatDateTime('yyyy/mm/dd',FieldByName('FIELD1').AsDateTime, DBConnector.FormatSettings));
-        ftFMTBcd : AssertEquals(testFmtBCDValues[i],BCDToStr(FieldByName('FIELD1').AsBCD{,DBConnector.FormatSettings}))
+        ftFMTBcd : AssertEquals(testFmtBCDValues[i],BCDToStr(FieldByName('FIELD1').AsBCD,DBConnector.FormatSettings))
       else
         AssertTrue('no test for paramtype available',False);
       end;
@@ -1770,7 +1770,8 @@ procedure TTestFieldTypes.TestParametersAndDates;
 // See bug 7205
 var ADateStr : String;
 begin
-  if SQLDbType in [interbase,mysql40,mysql41,mysql50,sqlite3] then Ignore('This test does not apply to this sqldb-connection type, since it doesn''t use semicolons for casts');
+  if not(SQLDbType in [postgresql,odbc,oracle]) then
+    Ignore('This test does not apply to this sqldb-connection type, since it doesn''t use semicolons for casts');
 
   with TSQLDBConnector(DBConnector).Query do
     begin

+ 15 - 10
packages/fcl-db/tests/toolsunit.pas

@@ -216,12 +216,13 @@ var DBConnectorRefCount: integer;
 
 constructor TDBConnector.create;
 begin
-  CreateFieldDataset;
-  CreateNDatasets;
-  FUsedDatasets := TFPList.Create;
   FFormatSettings.DecimalSeparator:='.';
+  FFormatSettings.ThousandSeparator:=#0;
   FFormatSettings.DateSeparator:='-';
   FFormatSettings.TimeSeparator:=':';
+  FUsedDatasets := TFPList.Create;
+  CreateFieldDataset;
+  CreateNDatasets;
 end;
 
 destructor TDBConnector.destroy;
@@ -292,27 +293,31 @@ const B: array[boolean] of char=('0','1');  // should be exported from some main
 
 var DBConnectorClass : TPersistentClass;
     i                : integer;
+    FormatSettings   : TFormatSettings;
 begin
   if DBConnectorRefCount>0 then exit;
+  
+  FormatSettings.DecimalSeparator:='.';
+  FormatSettings.ThousandSeparator:=#0;
+  
   testValues[ftString] := testStringValues;
   testValues[ftFixedChar] := testStringValues;
   testValues[ftTime] := testTimeValues;
+  testValues[ftDate] := testDateValues;
   testValues[ftFMTBcd] := testFmtBCDValues;
   for i := 0 to testValuesCount-1 do
     begin
     testValues[ftBoolean,i] := B[testBooleanValues[i]];
-    testValues[ftFloat,i] := FloatToStr(testFloatValues[i]);
+    testValues[ftFloat,i] := FloatToStr(testFloatValues[i],FormatSettings);
     testValues[ftSmallint,i] := IntToStr(testSmallIntValues[i]);
     testValues[ftInteger,i] := IntToStr(testIntValues[i]);
     testValues[ftLargeint,i] := IntToStr(testLargeIntValues[i]);
     // The decimalseparator was set to a comma for currencies and to a dot for ftBCD values.
-    // But why is not clear to me. For Postgres it works now, with a dot for both types.
-    // DecimalSeparator:=',';
-    DecimalSeparator:='.';
+    // DecimalSeparator for PostgreSQL must correspond to monetary locale set on PostgreSQL server
+    // Here we assume, that locale on client side is same as locale on server
+        
     testValues[ftCurrency,i] := CurrToStr(testCurrencyValues[i]);
-    // DecimalSeparator:='.';
-    testValues[ftBCD,i] := CurrToStr(testCurrencyValues[i]);
-    testValues[ftDate,i] := testDateValues[i];
+    testValues[ftBCD,i] := CurrToStr(testCurrencyValues[i],FormatSettings);
     end;
 
   if dbconnectorname = '' then raise Exception.Create('There is no db-connector specified');