From 064ecf3d6ce8f3937f0db7f77f9fcdf6642738cc Mon Sep 17 00:00:00 2001 From: marco Date: Mon, 1 Aug 2011 16:22:18 +0000 Subject: [PATCH] * fix decimalseparator locale issues in fcl-db testsuite, mantis #19564 git-svn-id: trunk@18051 - --- packages/fcl-db/tests/sqldbtoolsunit.pas | 2 +- packages/fcl-db/tests/testdbbasics.pas | 5 ++--- packages/fcl-db/tests/testfieldtypes.pas | 11 ++++++----- packages/fcl-db/tests/toolsunit.pas | 25 ++++++++++++++---------- 4 files changed, 24 insertions(+), 19 deletions(-) diff --git a/packages/fcl-db/tests/sqldbtoolsunit.pas b/packages/fcl-db/tests/sqldbtoolsunit.pas index 7a8a7c2bdd..d7db9281dc 100644 --- a/packages/fcl-db/tests/sqldbtoolsunit.pas +++ b/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; diff --git a/packages/fcl-db/tests/testdbbasics.pas b/packages/fcl-db/tests/testdbbasics.pas index 525fcbbc44..0c9206fd7d 100644 --- a/packages/fcl-db/tests/testdbbasics.pas +++ b/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; diff --git a/packages/fcl-db/tests/testfieldtypes.pas b/packages/fcl-db/tests/testfieldtypes.pas index 890df02f48..98c989c5dc 100644 --- a/packages/fcl-db/tests/testfieldtypes.pas +++ b/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 diff --git a/packages/fcl-db/tests/toolsunit.pas b/packages/fcl-db/tests/toolsunit.pas index 8131071ff8..b37879c917 100644 --- a/packages/fcl-db/tests/toolsunit.pas +++ b/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');