Problem with FormatBcd
Posted: 11.03.2021, 23:59
I see in viewtopic.php?f=50&t=131587&p=164419&hi ... CD#p164419, there is already a bug report for FPC FormatBcd. I have a similar problem, but not the same, so I create a new topic.
I changed a big project from old Zeos trunk version to current 8.0 patches branch. I use 64bit FPC 3.2.0 Lazarus Trunk on Windows 7 and communicate with PostgreSQL 10.
On a table I have a value NUMERIC. With this field I got a rangecheck error.
I debugged the issue and can see for a value 0,014 there this tBCD is set:
With this value FormatBCD('#,###0.000', BCD) raise a range check error. If I use BCDToStr(BCD), the value is converted to a string.
If I use BCD := StrToBCD('0,014'), I can see this tBCD is set:
With this value FormatBCD('#,###0.000', BCD) and BCDToStr(BCD) are working fine.
If I use BCD := StrToBCD('0,14'), I can see this tBCD is set:
This is mostly similar to first case and works for both functions FormatBCD('#,###0.000', BCD) and BCDToStr(BCD).
Now I don't know, if this is a bug in TZAbstractRODataset(DataSet).FResultSet.GetBigDecimal with a wrong comma position or is this BCD value valid and there is a bug in fpc FormatBCD or do I miss something?!
Simple test also a workaround patch added, so I can use Zeos for now.
I changed a big project from old Zeos trunk version to current 8.0 patches branch. I use 64bit FPC 3.2.0 Lazarus Trunk on Windows 7 and communicate with PostgreSQL 10.
On a table I have a value NUMERIC. With this field I got a rangecheck error.
I debugged the issue and can see for a value 0,014 there this tBCD is set:
Code: Select all
FillChar(BCD{%H-}, SizeOf(BCD), 0);
BCD.Fraction[0] := 20;
BCD.Precision := 2;
BCD.SignSpecialPlaces := 3;
If I use BCD := StrToBCD('0,014'), I can see this tBCD is set:
Code: Select all
FillChar(BCD{%H-}, SizeOf(BCD), 0);
BCD.Fraction[0] := 1;
BCD.Fraction[1] := 64;
BCD.Precision := 3;
BCD.SignSpecialPlaces := 3;
If I use BCD := StrToBCD('0,14'), I can see this tBCD is set:
Code: Select all
FillChar(BCD{%H-}, SizeOf(BCD), 0);
BCD.Fraction[0] := 20;
BCD.Precision := 2;
BCD.SignSpecialPlaces := 2;
Now I don't know, if this is a bug in TZAbstractRODataset(DataSet).FResultSet.GetBigDecimal with a wrong comma position or is this BCD value valid and there is a bug in fpc FormatBCD or do I miss something?!
Simple test also a workaround patch added, so I can use Zeos for now.