Page 1 of 1

Type mismatch expecting: Currency actual: extended

Posted: 11.05.2019, 18:18
by louis
Hello,
in Zeos 7.2.4 I get a:
"Type mismatch for field xxx, expecting: Currency actual: Extended."

In Firebird 2.5 Table1, "PREZZO" is a field of type Numeric(18, 4).

In this query:

Code: Select all

SELECT
  *
FROM
  TABLE1
In Fields Editor a TCurrencyField is added for field PREZZO.

In this query:

Code: Select all

SELECT
 PREZZO
FROM
  TABLE1
In Fields Editor a TExtendedField is added for field PREZZO.

Why?

I discovered this behaviour because I updated from 7.2.? (how I verify build?) to 7.2.4 and my application raises a lot of Type mismatch exceptions.

What I can verify?

Thanks.

Re: Type mismatch expecting: Currency actual: extended

Posted: 13.05.2019, 09:31
by marsupilami
Hello Louis,

it seems that you have persistent fields in your application. Right-click on the TZQuery where this happens. A menu appears where you can choose to open the Field Editor. In the field editor remove the fields and add them again.

Using TCurrencyField for numeric values was a problem in early Zeos 7.2 development. We changed these places to use TFloatField or TExtendedField later on.

Note: I suggest to avoid persistent fields as much as you can because this will lead to problems like this. Even more so if you decide to use more than one type of database in your application. In my applications I use the AfterOpen event of TZQuery to set fields properties like this:

Code: Select all

  Query.FieldByName('Field_1').Visible := False;
  (Query.FieldByName('Field_2') as TExtendedField).Currency := True;

Re: Type mismatch expecting: Currency actual: extended

Posted: 13.05.2019, 11:20
by louis
Using TCurrencyField for numeric values was a problem in early Zeos 7.2 development. We changed these places to use TFloatField or TExtendedField later on.

But, in Zeos 7.2.4 stable, why if I have this query:

Code: Select all

SELECT
  *
FROM
  TABLE1
I gain a TFloatField (I had mistake writing TCurrencyField, TCurrencyField is on zeos 7.2.0b).

while if the query is:

Code: Select all

SELECT
  PREZZO
FROM
  TABLE1
I gain TExtendedField?

In both cases I should get TExtendedField. Why not?

I see that my post seems to be a duplicate of [url] http://zeoslib.sourceforge.net/viewtopi ... 40&t=92540 [/ url] but it's different because I want to understand why I get TFloatField or TExtendetField for the same FIELD on the same TABLE as the query is written.

Thanks.

Re: Type mismatch expecting: Currency actual: extended

Posted: 13.05.2019, 13:07
by marsupilami
Hello Louis,

this shouldn't happen. Could you please provide the complete DDL (create table ...) for your table?

Best regards,

Jan

Re: Type mismatch expecting: Currency actual: extended

Posted: 13.05.2019, 14:13
by louis
marsupilami wrote:this shouldn't happen. Could you please provide the complete DDL (create table ...) for your table?
Yes, FB 2.5:

Code: Select all

CREATE DOMAIN CURRENCY_D
 AS Numeric(18,4)
 DEFAULT 0.00
 NOT NULL
;

CREATE TABLE TABLE1
(
  ID Integer NOT NULL,
  PREZZO CURRENCY_D DEFAULT 0.00,
  CONSTRAINT ID_PK PRIMARY KEY (ID)
Thanks.
Regards.

Re: Type mismatch expecting: Currency actual: extended

Posted: 14.05.2019, 21:46
by marsupilami
I was able to verify this problem and created a ticket on the bugtracker (#351) as well as a test to demonstrate the problem in our test suites.

Re: Type mismatch expecting: Currency actual: extended

Posted: 16.05.2019, 09:22
by marsupilami
Hello louis,

it seems that EgonHugeist checked in a solution. Could you please check if the problem is solved in the current 7.2-testing branch on SVN?
Best regards,

Jan

Re: Type mismatch expecting: Currency actual: extended

Posted: 17.05.2019, 14:05
by louis
marsupilami wrote:it seems that EgonHugeist checked in a solution. Could you please check if the problem is solved in the current 7.2-testing branch on SVN?
Ok, now in both cases I get a field of type TExtendedField.

But, why, in Zeos, is not safe to use TCurrencyFields?

Thanks.

Regards.

Re: Type mismatch expecting: Currency actual: extended

Posted: 20.05.2019, 07:48
by marsupilami
Hello Louis,

it is safe to use currency fields in Zeos. But Firebird doesn't have a currency or money data type so there is nothing there that we can map to be a TCurrencyField by default.

Best regards,

Jan

Re: Type mismatch expecting: Currency actual: extended

Posted: 24.05.2019, 17:07
by EgonHugeist
louis wrote:
marsupilami wrote:it seems that EgonHugeist checked in a solution. Could you please check if the problem is solved in the current 7.2-testing branch on SVN?
Ok, now in both cases I get a field of type TExtendedField.

But, why, in Zeos, is not safe to use TCurrencyFields?

Thanks.

Regards.
The TCurrencyField is a bit messleading. That field-descendant uses double precision floats to represent the numbers.
The TBCDField is what you are looking for. On 7.2 we've a beahvior lock but it's supported already on 7.3.
Fields with higher scale/precision than a currency can have will be mapped to FmtBCD next weeks on 7.3 too. The most conversion methods for all drivers (except ASA -> no idea how) i've ready inbetween.
The TExtended field will no longer be used on 7.3 if the switch is done.
Stay tuned..