Subject Re: [IBO] Is CURRENCY field column attributes ignored?
Author Marco Menardi
--- In IBObjects@y..., "Geoff Worboys" <geoff@t...> wrote:
> Hi Marco,
> > I've a mynum NUMERIC(15,2), defined as CURRENCY in the
> > query. Having a look at IBA_Column.IMP i can see that
> > when I edit that field in a IB_Edit and exiting the
> > value is assigned to the field, it's called the code
> > for a generi floating field
> >
> > TIB_ColumnNumeric.SetAsString(
> > ...
> > try
> > Value := StrToFloat( tmpVal );
> > except
> > ...
> >
> > so a value like 21321545000010,00 is accepted (!!! it's 16
> digits+00).
> AFAIK this is actually consistent with IB/FB - in that field
> is not honoured - presumably because they have only just gotten
> to actually storing the information, and since it is not available
> the client (without lots of extra work) there is no way for IBO to
> validate this properly.

But QuickDesk or IBConsole do not allow that. I've entered values with
IBO that did a "conversion error" in IBConsole and QuickDesk when I've
tried to read that record. IN QuickDesk I was able to put another
value in the field, in IBConsole I was not, since the record was not
displayed after the error.

> > But if you try to set this value to the field with
> > Field.AsCurrency := 21321545000010
> > an error occurs (welcome!)
> What error and when does it occur? Do you have a callstack for the
> error?

The "offending" code is:

SQL_INT64_: begin
for ii := 1 to -SQLScale do tmpVal := tmpVal * 10;

So you can see that the field value, if you have scale 2, is
multiplied by 100 before assignment. So if Delphi currency max is, for
instance, 1000,99 and current value is 200,12, here the value is:
200,12 * 100 = 20000,12 ----> overflow.
I've had a look at IBX code and they directly assign the "memory"
image of the currency (already scaled to INT64) to the buffer, as long
as I can understand.

BTW, is there a easy way to copy the contents of the Delphi stack

> Please ensure that you tell us the server type and version and the
> delphi/bcb version that you are using. All these factors are
> to know what to expect in a given situation with numeric/decimal
> types - since the processing and storage types vary accordingly.

IB 6.01, D6pro sp1
> > I don't understand this situation... and what's the use
> > of CURRENCY column attribute?
> It is only used to manage the default displaytext. If you have your
> own displayformat or editmask then the attribute is ignored. It
> not have any impact on the value processing.

But the beauty of currency is that they have perfect precision of
decimals, since they are stored as scaled integer (INT64). Apart of
Currency attribute, the storage from IB_Text (or my IB_Currency) to
interbase field should not pass through any Float conversions as far
as I understand.

> Geoff Worboys
> Telesis Computing
Marco Menardi