Invalid class TypeCast Error

Hi,

I'm moving an Aurelius App from using FireBird to Oracle Express, I'm using UniDAC for database access, I have duplicated the FireBird DB into Oracle, when triying to acces data using Aurelis I get the following Error:
"Invalid class typecast." then I get "Could not convert database value to object member.
class name: TMODELO
Columna name: ID
Attribute name: FID
Database value: 1"

* ID is defined as integer
** What I have Noticed is that the exception is raised on "TMappingExplorer.SetValue" and Value has Kind = tkFloat.

Any hint?

Thanks In Advance,

Omar Zelaya

Hi,

 There is a configuration in UniDac (and most database-access components) that considers Oracle NUMBER fields as integer, instead of floats. The equivalent of the old ENABLE INTEGERS=TRUE of the BDE. You can turn it on to make unidac bring fields as integer so Aurelius can safely read them.

Hi Wagner,

EnableIntegers is allready set to True, so thats not the case.

* On procedure TMappingExplorer.SetColumnDbValue(Entity: TObject; Column: TColumn; Value: Variant);
Column.FieldType is ftInteger

 

Thanks in advance,

Omar Zelaya

You said yourself that value retrieved from database is of type tkFloat? That's a typical error that is solved that way. Can you confirm that a simple direct select using unidac brings an integer field instead of a float field? 

Hi Wagner,

The field in Oracle in declared as Integer.

Omar Zelaya

But what Oracle version is that? As far as I know, there is no such INTEGER type in Oracle, just NUMBER? Can you please perform the test I mentioned?

Hi Wagner,

What I have said is that the Variant Variable Value is Kind tkFloat and Column.FieldType is ftInteger, and the field is delcared as integer in orcacleand not numeric, I'm triying to find out where and why the ID DB Field Value is assigned as tkfloat to the Variant Var Value.

Just to Test I have add the following code to TUtils.VariantToValue(Value: Variant): TValue;
...
case VarTypeToDataType(VarType(Value)) of  // btw VarType(Value)) returns varDouble
    ftFloat:
      begin
        if TryStrToInt(Value, IntAux) then
          Result := TValue.From<integer>(IntAux)
      end;
...
And it works Ok, so the problem is that Value is kind tkFloat and not tkInteger.
Thanks in Advance,

Omar Zelaya

Hi,

Is Oracle DataBase Express Edition 11g Release 2
running a query the ID Field is retrived as integer.
 

Yes, that's what is causing the problem, and this is usually just the underlying database-access component. That's why I mentioned you do a test with the same UniDac connection you are using with Aurelius. The mechanism of Aurelius to get that field is very direct. It just creates a TUniQuery, set the SQL, open it, and get the field value as a variant using the Value property:


Value := UniQuery1.FIeldByName('ID').Value;

from what I'm seeing and understood, in that point, UniQuery is returning a variant value of type tkFloat. That's the issue, that's why I asked you to do such tests with a TUniQuery component directly.
And I mentioned that there might be configurations in UniDac to make it return such variant as an tkInteger, not tkFloat. Can you please try these options:

EnableIntegers=True
EnableLargeInt=True
PrecisionLargeInt=20

Hi Wagner,

Yes, TUniQuery Is returning a tkFloat and the settings you sugested didnt make any diference.

Going to ask on UniDac Forum about the tkFloat and Integer data field type on Oracle Express.

Thanks for your help.

Omar Zelaya