Page 1 of 1

want boolean but get largeint

Posted: Mon 23 Sep 2013 15:03
by jkuiper2105
This selection shall give me true or false in delphi:

Code: Select all

SELECT i.id,
       if((SELECT count(ont.id) FROM delivery ont 
             WHERE ont.id = i.id) > 0,true, false) 
       AS deliverybool
FROM  invoice i
When I create the fielddefinitions in designtime, the field deliverybool is created as TLargeintfield and not as TBooleanField.

Is this a behavior of Delphi of TMyQuery?

MySQL converts true or false as 1 or 0, but as far as I know TMyQuery will convert it as boolean.

Re: want boolean but get largeint

Posted: Tue 24 Sep 2013 15:24
by VladimirK
Such behaviour is correct because in this case MySQL returns the bigint type for the deliverybool field.
To avoid the problem, you can use the Data Type Mapping functionality.
Here is a code example:

Code: Select all

MyQuery1.DataTypeMap.Clear;
MyQuery1.DataTypeMap.AddFieldNameRule('deliverybool', ftBoolean);
MyQuery1.Open;
You can read more about Data Type Mapping in the MyDAC documentation: http://www.devart.com/mydac/docs/index. ... apping.htm

Re: want boolean but get largeint

Posted: Wed 25 Sep 2013 08:03
by jkuiper2105
Thanks.
That's a one I didn't know.

first I got an error, but cleared my fields in fieldsdef in Designtime.
Now I have a boolean instead of largeint.

This is a very powerful feature.

Re: want boolean but get largeint

Posted: Wed 25 Sep 2013 12:21
by VladimirK
Data Type Mapping affects field types. Therefore, to avoid errors, you should remove persistent fields before adding new mapping rules or changing existent ones.