Board index » delphi » BCD overflow error with Oracle calculated fields
Michael Winter
![]() Delphi Developer |
BCD overflow error with Oracle calculated fields2003-12-16 04:39:50 PM delphi226 Hia all, some of you might know the problem when you issue a statement like select 1/3 from dual to an Oracle DB from within a TSQLDataSet: .Open works perfectly, but as soon as you try to get the value from Fields[0], as whatever type you try (.AsFloat, .AsString, .AsVariant), you end up with a EDatabaseError exception saying 'BCD overflow'. The reason is somewhere in the NormalizeBcd() function in unit FMTBcd. In the given case, it is called to convert the InBCD (Precision: 41, SignSpecialPlaces: 40) into an OutBCD using parameters Prec = 32 and Scale = 8. Since output precision (the place available, if I understand that correctly) is smaller then input precision, the following statement if (Prec < Word(InBcd.Precision)) and (SignificantIntDigits(pIn, Word(InBcd.Precision))>Prec) then Result := False sets Result to false which later causes the exception. Although I don't know exactly what SignificantIntDigits should do, I assume it should return the number of digits before the decimal point. In that case, the 2nd parameter of would be wrong and should be replaced by Word(InBcd.Precision - DecDigits) I've changed this (well, not in the Borland unit, I use a kind of 'runtime patch' which simply changes the code to a jump to a replacement function), and it seems to work well. Question (1) is: Is my assumption above right, or will I run into other problems? There are some other bugs or restrictions with this FMTBcd stuff. One is that e. g. 1E31 (in Oracle) is returned as 1E23 in Delphi (that makes it impossible to work with such numbers abow 1E23, of course), the other one is that 1E32 and above end up with that 'BCD overflow' exception again. What I didn't mention yet is that in my current project I have to read from external DBs (i. e. I can not manipulate their field structure) whatever fields there are. Question (2): How can I force Delphi/DBExpress to create a Double field instead of this FMTBcd for Oracle NUMBER fields? TIA -Michael |