Field type change in table

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
kneighbour
Posts: 77
Joined: Wed 08 Oct 2008 04:55

Field type change in table

Post by kneighbour » Fri 10 Aug 2018 01:48

I use Firebird 3 and Delphi XE7.
I have a problem in that I have changed a lot of primary field types in the Firebird tables from Integer to LargeInt. The problem occurs in my Delphi apps when I have persistent fields in the UniTable or UniQuery components. In general I have gone through and removed persistent fields, but there are a couple of occasions where persistent fields are required. This is when I am using calculated or lookup fields as part of the dataset.

The actual problem is that I have customers on the old data structure where these fields are of type Integer, and some customers where the fields are of type Largeint. When the Unitable opens you get an exception of the type "Field type expected to be Largeint but found type Integer". I have tried to trap the exception and simply carry on, but it does not seem to work. The UniTable does not load any data. If I can get the component to simply ignore this error, I would be happy with that - is this possible?

I have seen another post in this forum describing how to add calculated fields at runtime, which seems to be a way to resolve this. ie I need to create all the persistent fields at runtime.
ie

Code: Select all

 FSUM := TIntegerField.Create(UniQuery1);
  FSUM.FieldName := 'Calc';
  FSUM.FieldKind := fkCalculated;
  FSUM.DataSet := UniQuery1;
  UniQuery1.Open;
The problem is that you need to have defined the FSUM variable as FSUM:TIntegerField or FSUM:TLargeIntField and that will not work. Is there some way to leave the definition of the field until I define it in code? ie define FSUM :TVariantField.

Any thoughts along these lines? My preferred solution is to simply trap the exception when opening the table and to carry on.

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: Field type change in table

Post by ViktorV » Fri 10 Aug 2018 10:18

"Type mismatch for field 'Field Name' expecting: LargeInt actual: Integer" error means that you have a persistent TLargeInt field in your dataset but the UniDAC returns the TInteger field.
To solve the problem you can remove the persistent fields.
Also, you can map data of the system type LargeInt using the 'Field Name' of the needed columns:

Code: Select all

Query.DataTypeMap.AddFieldNameRule(YourFieldName, ftLargeInt);

kneighbour
Posts: 77
Joined: Wed 08 Oct 2008 04:55

Re: Field type change in table

Post by kneighbour » Tue 14 Aug 2018 05:35

Brilliant! That solves my problem perfectly. Many thanks.

Stellar
Devart Team
Posts: 496
Joined: Tue 03 Oct 2017 11:00

Re: Field type change in table

Post by Stellar » Mon 20 Aug 2018 10:22

Glad to see that the issue was resolved.
Feel free to contact us if you have any further questions about our products.

Post Reply