Subject Re: [IBO] Is CURRENCY field column attributes ignored?
Author Marco Menardi
--- In IBObjects@y..., "Geoff Worboys" <geoff@t...> wrote:
> > Reading IB6 Data definition guide, you discover that,
> > for IBO6 and above, numeric data are ALWAYS stored as
> > integer. The precision determinates if INTEGER or
> > INT64 is used. Since IBO knows about data byte
> > occupation in the database (SQLSize, or something like
> > that), EVERY numeric() must be stored as integer.
>
> Its actually the SQLType that is used (SQL_SHORT, SQL_LONG,
SQL_INT64
> etc). IBO is already handling the situation in this regard.
>
>
> > So there should be a code like:
> > tmpINT64 := CurrencyFieldValue * (Power10Int(scale))
>
> We want to avoid mixing currency (integer) and extended (floating
> point) if possible. Anyway, you will see that IBO is already doing
> something similar.

Similar, but not the same:
IBO does, roughly, something like
tmpCurrency := for i=1 to scale: tmpCurrency := tmpCurrency * 10
this brings tmpCurrency to overflow very easy!
Let's say, for istance, that the limit (overflow) of currency is 1000,
and that we have scale 2 and the number 30.
My code would produce:
tmpINT64=30*100 ----> tmpINT64=3000 that is OK and will be ok when
read since it will be scaled down
IBO code in the loop does in two steps:
tmpCurrency := tmpCurrency * 10 --> Currency = 300
tmpCurrency := tmpCurrency * 10 --> Currency = 3000 OVERFLOW!!!
So my code and IBO are not the same at all.


> This does not negate the fact that an overflow can occur if the type
> was NUMERIC(18,2) - if database does not restrict the input via a
> check on the domain/field to only 14 digits of whole number.
>
We must round to scale when assigning to tmpINT64, so if Delphi
currency has 3 decimals and numeric(15,2) is used, it will be rounded
to 2 decimals.

>
> Geoff Worboys
> Telesis Computing

Regards
Marco Menardi