want boolean but get largeint

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
jkuiper2105
Posts: 20
Joined: Wed 18 Sep 2013 14:10

want boolean but get largeint

Post by jkuiper2105 » Mon 23 Sep 2013 15:03

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.

VladimirK
Devart Team
Posts: 16
Joined: Tue 24 Sep 2013 09:19

Re: want boolean but get largeint

Post by VladimirK » Tue 24 Sep 2013 15:24

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

jkuiper2105
Posts: 20
Joined: Wed 18 Sep 2013 14:10

Re: want boolean but get largeint

Post by jkuiper2105 » Wed 25 Sep 2013 08:03

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.

VladimirK
Devart Team
Posts: 16
Joined: Tue 24 Sep 2013 09:19

Re: want boolean but get largeint

Post by VladimirK » Wed 25 Sep 2013 12:21

Data Type Mapping affects field types. Therefore, to avoid errors, you should remove persistent fields before adding new mapping rules or changing existent ones.

Post Reply