Page 1 of 1
Porting ODAC to UNIDAC: Type Mismatch problem with AsFloat and AsLargeInt
Posted: Mon 11 Apr 2016 07:36
by David Lipschitz
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?
Re: Porting ODAC to UNIDAC: Type Mismatch problem with AsFloat and AsLargeInt
Posted: Mon 11 Apr 2016 07:43
by David Lipschitz
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.
Re: Porting ODAC to UNIDAC: Type Mismatch problem with AsFloat and AsLargeInt
Posted: Mon 11 Apr 2016 13:20
by AlexP
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.
Re: Porting ODAC to UNIDAC: Type Mismatch problem with AsFloat and AsLargeInt
Posted: Mon 11 Apr 2016 13:35
by David Lipschitz
Thanks Alex.
Must I do this for each field, or can I do it once for each application?
Regards
David
Re: Porting ODAC to UNIDAC: Type Mismatch problem with AsFloat and AsLargeInt
Posted: Mon 11 Apr 2016 13:54
by David Lipschitz
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;
Re: Porting ODAC to UNIDAC: Type Mismatch problem with AsFloat and AsLargeInt
Posted: Tue 12 Apr 2016 08:37
by AlexP
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.
Re: Porting ODAC to UNIDAC: Type Mismatch problem with AsFloat and AsLargeInt
Posted: Thu 14 Apr 2016 13:38
by David Lipschitz
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
Re: Porting ODAC to UNIDAC: Type Mismatch problem with AsFloat and AsLargeInt
Posted: Tue 19 Apr 2016 06:14
by AlexP
You are welcome. Feel free to contact us if you have any further questions.