Porting ODAC to UNIDAC: Type Mismatch problem with AsFloat and AsLargeInt

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
David Lipschitz
Posts: 9
Joined: Fri 23 Mar 2012 04:38
Location: Cape Town, South Africa
Contact:

Porting ODAC to UNIDAC: Type Mismatch problem with AsFloat and AsLargeInt

Post by David Lipschitz » Mon 11 Apr 2016 07:36

I am porting an application to work with both Oracle and SQL Server. It seems like the best approach is to move from ODAC to UniDac, but I have hit a problem.

I am getting EDatabaseError ... Type mismatch for field '<fieldname>", expecting: Float actual: LargeInt.

I can't just change all my Float fields to LargeInts because some of the Floats are Actually floats.

Why does this problem exist and what do you suggest I do about it?

David Lipschitz
Posts: 9
Joined: Fri 23 Mar 2012 04:38
Location: Cape Town, South Africa
Contact:

Re: Porting ODAC to UNIDAC: Type Mismatch problem with AsFloat and AsLargeInt

Post by David Lipschitz » Mon 11 Apr 2016 07:43

Note that some of the Float fields are integers, but when adding them in the BDE or ODAC they come up automatically as Float fields.

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: Porting ODAC to UNIDAC: Type Mismatch problem with AsFloat and AsLargeInt

Post by AlexP » Mon 11 Apr 2016 13:20

Hello,

This behavior is due to different definition of field types in ODAC and UniDAC depending on the field size in a database.
To solve the issue, you should set mapping rules for the needed fields. For example, in ODAC, a NUMBER(18, 0) field in the database will be defined as TFloatField, and in UniDAC - as TLargeintField. To make behavior identical, set the following rule:

Code: Select all

  UniTable1.DataTypeMap.AddDBTypeRule(oraNumber, ftFloat, 18);
or set it in the UniQuery edit form on the DataTypeMapping tab.

David Lipschitz
Posts: 9
Joined: Fri 23 Mar 2012 04:38
Location: Cape Town, South Africa
Contact:

Re: Porting ODAC to UNIDAC: Type Mismatch problem with AsFloat and AsLargeInt

Post by David Lipschitz » Mon 11 Apr 2016 13:35

Thanks Alex.

Must I do this for each field, or can I do it once for each application?

Regards
David

David Lipschitz
Posts: 9
Joined: Fri 23 Mar 2012 04:38
Location: Cape Town, South Africa
Contact:

Re: Porting ODAC to UNIDAC: Type Mismatch problem with AsFloat and AsLargeInt

Post by David Lipschitz » Mon 11 Apr 2016 13:54

Hi Alex

I found this

fAADataBase.DataTypeMap.AddDBTypeRule(oraNumeric, 11, rlAny, 0, 0, ftLargeint);

Can I use if for the database?

but where are OrNumeric, rlAny and ftLargeInt defined?

Regards
David

PS:
Here is my code:

TBaseDataObjectDAC = Class (TInterfacedObject)
private
{ Private Declarations }

fAADataBase: TUniConnection;
...


if not Assigned(fAADatabase) then
begin
fAADataBase:= TUniConnection.Create( nil );
fAADataBase.DataTypeMap.AddDBTypeRule(oraNumeric, 11, rlAny, 0, 0, ftLargeint);
//UniTable1.DataTypeMap.AddDBTypeRule(oraNumber, ftFloat, 18);
end;

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: Porting ODAC to UNIDAC: Type Mismatch problem with AsFloat and AsLargeInt

Post by AlexP » Tue 12 Apr 2016 08:37

To apply mapping rules "globally", you should set them in TUniConnection - then the rule will be applied to all DataSets related to this UniConnection.
The oraNumber type is declared in the OraDataTypeMapUni module, the rlAny type - in MemDS, the ftLargeint type - in the DB.

David Lipschitz
Posts: 9
Joined: Fri 23 Mar 2012 04:38
Location: Cape Town, South Africa
Contact:

Re: Porting ODAC to UNIDAC: Type Mismatch problem with AsFloat and AsLargeInt

Post by David Lipschitz » Thu 14 Apr 2016 13:38

Thanks Alex.

At the moment I am changing the relevant types to LongInts where applicable.

I'll keep you posted as to my progress.

Regards
David

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: Porting ODAC to UNIDAC: Type Mismatch problem with AsFloat and AsLargeInt

Post by AlexP » Tue 19 Apr 2016 06:14

You are welcome. Feel free to contact us if you have any further questions.

Post Reply