BOOLEAN Calculated Field

Discussion of open issues, suggestions and bugs regarding Virtual Data Access Components for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Aggie85
Posts: 95
Joined: Wed 11 Nov 2015 17:03

BOOLEAN Calculated Field

Post by Aggie85 » Wed 12 Jul 2017 04:36

Howdy!

I have a calculated BOOLEAN column that I want to return with a SELECT set. Since BOOLEANs are stored as INTEGERs, the values are 0 for False and 1 for True.

That is,

SELECT <field 1>,<field 2>,0 AS Enabled
FROM <Table>

When I get the result set from TVirtualQuery and I try to copy the results to a TkbmMemTable, I am getting an error on the BOOLEAN field in the TkbmMemTable that 0 is NOT valid Boolean value for column 'Enabled'.

Any suggestions on how to fix this? All actual table boolean columns work fine.

All the best,

Aggie85

MaximG
Devart Team
Posts: 1822
Joined: Mon 06 Jul 2015 11:34

Re: BOOLEAN Calculated Field

Post by MaximG » Wed 12 Jul 2017 07:58

Thank you for the information. Unfortunately, we could not reproduce the problem according to your description. Please compose and send us via the e-support form (https://www.devart.com the "Support"\"Request Support" menu) a small complete sample in which the problem occurs.

Aggie85
Posts: 95
Joined: Wed 11 Nov 2015 17:03

Re: BOOLEAN Calculated Field

Post by Aggie85 » Wed 12 Jul 2017 12:05

Good day Maxim!

The problem is the constant field I am adding in the SELECT statement returns fine from TVirtualQuery, but when I try to copy the returned data to a TkbmMemTable dataset, I get the error.

I have even tried

SELECT <field 1>,<field 2>,(CAST 0 AS BOOLEAN) AS Enabled
FROM <Table>

And I get the same error. How can I get TVirtualQuery to make sure Enabled is a BOOLEAN in the return dataset (the field doesn't exist in any underlying dataset in the SELECT - it is a calculated field for the resulting dataset the data will be copied into).

Thanks,

Aggie85

MaximG
Devart Team
Posts: 1822
Joined: Mon 06 Jul 2015 11:34

Re: BOOLEAN Calculated Field

Post by MaximG » Wed 12 Jul 2017 14:04

To execute the described queries using VirtualQuery, you can use DataTypeMapping. For this, before opening the query, create the following rule :

Code: Select all

VirtualQuery.DataTypeMap.AddFieldNameRule('Enabled', ftBoolean);

Aggie85
Posts: 95
Joined: Wed 11 Nov 2015 17:03

Re: BOOLEAN Calculated Field

Post by Aggie85 » Wed 12 Jul 2017 14:29

I will add it to my framework for special occasions when needed.

Thanks,

Aggie85

Aggie85
Posts: 95
Joined: Wed 11 Nov 2015 17:03

Re: BOOLEAN Calculated Field

Post by Aggie85 » Wed 12 Jul 2017 20:11

The TVirtualQuery's DataTypeMap did the trick.

Thanks,

Aggie85

MaximG
Devart Team
Posts: 1822
Joined: Mon 06 Jul 2015 11:34

Re: BOOLEAN Calculated Field

Post by MaximG » Thu 13 Jul 2017 07:10

We are glad that we could find the solution, which helped to implement your projects.

Aggie85
Posts: 95
Joined: Wed 11 Nov 2015 17:03

Re: BOOLEAN Calculated Field

Post by Aggie85 » Thu 13 Jul 2017 17:04

Most thanks!

All the best,

Aggie85

Post Reply