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

git-svn-id: trunk@18051 -
This commit is contained in:
marco 2011-08-01 16:22:18 +00:00
parent 6d5e16d9e6
commit 064ecf3d6c
4 changed files with 24 additions and 19 deletions

View File

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

View File

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

View File

@ -274,7 +274,7 @@ begin
TestFieldDeclaration(ftBCD,sizeof(Currency)); TestFieldDeclaration(ftBCD,sizeof(Currency));
for i := 0 to testValuesCount-1 do 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 with TSQLDBConnector(DBConnector).Query do
begin begin
@ -614,7 +614,7 @@ begin
TestFieldDeclaration(ftFloat,sizeof(double)); TestFieldDeclaration(ftFloat,sizeof(double));
for i := 0 to testValuesCount-1 do 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 with TSQLDBConnector(DBConnector).Query do
begin begin
@ -803,7 +803,7 @@ begin
Params.ParamByName('field1').AsString:= testDateValues[i] Params.ParamByName('field1').AsString:= testDateValues[i]
else else
Params.ParamByName('field1').AsDateTime:= StrToDate(testDateValues[i],'yyyy/mm/dd','-'); 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 else
AssertTrue('no test for paramtype available',False); AssertTrue('no test for paramtype available',False);
end; end;
@ -826,7 +826,7 @@ begin
ftString : AssertEquals(testStringValues[i],FieldByName('FIELD1').AsString); ftString : AssertEquals(testStringValues[i],FieldByName('FIELD1').AsString);
ftTime : AssertEquals(testTimeValues[i],DateTimeToTimeString(FieldByName('FIELD1').AsDateTime)); ftTime : AssertEquals(testTimeValues[i],DateTimeToTimeString(FieldByName('FIELD1').AsDateTime));
ftdate : AssertEquals(testDateValues[i],FormatDateTime('yyyy/mm/dd',FieldByName('FIELD1').AsDateTime, DBConnector.FormatSettings)); 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 else
AssertTrue('no test for paramtype available',False); AssertTrue('no test for paramtype available',False);
end; end;
@ -1770,7 +1770,8 @@ procedure TTestFieldTypes.TestParametersAndDates;
// See bug 7205 // See bug 7205
var ADateStr : String; var ADateStr : String;
begin 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 with TSQLDBConnector(DBConnector).Query do
begin begin

View File

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