Problem with boolean parameter in FB3

Discussion of open issues, suggestions and bugs regarding IBDAC (InterBase Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
helste
Posts: 6
Joined: Wed 21 Sep 2016 14:02

Problem with boolean parameter in FB3

Post by helste » Mon 04 Mar 2019 10:33

I have a problem, that came up recently, when trying to pass boolean parameters to a stored procedure in Firebird 3.

For boolean I use a domain "dom_boolean" that is declared as a char (1) and holds 'T' for true and 'F' for false.
Now I have a stored procedure with boolean parameters. Somthing like this:

create procedure someprocedure (par1 dom_boolean)

returns (result integer) as

begin
.....
suspend;
end^

In Delphi I use it like:

somebooleanvariable := true;
.....
query.sql.text := 'select result from someprocedure (:par1)';
query.parambyname ('par1').asboolean := somebooleanvariable;
query.open;

In Firebird 2.5 that works fine. In Firebird 3.0 I get an exception with something like that "arithmetic exception, numeric overflow, or string truncation string right truncation" and it claims that length should by 4 but is only 1.
So it looks to me, that the type of the boolean parameter should be a 4 byte type and not a 1 byte, like my dom_boolean.

Unfortunately that worked for years with Firebird 2.5 and I have many of that in my projects.
I made a quick and dirty workaround to use parambyname ('par1').asstring and assign 'T' or 'F' depending if it should be true or false, but that is a bit of a mess, because I always have to pay attention to not use asboolean for parameters and

query.parambyname ('par1').asboolean := somebooleanvariable;

is way better than

if somebooleanvariable then
query.parambyname ('par1').asstring := 'T'
else
query.parambyname ('par1').asstring := 'F';

Any suggestions how to deal with that or explanation why this has changed with FB3?

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

Re: Problem with boolean parameter in FB3

Post by ViktorV » Mon 04 Mar 2019 15:01

Thank you for the information.
We investigated the problem and found that this error is caused by the specifics of the Firebird 3 functionality, in which the BOOLEAN data type was added. We investigated this feature and inform you about the result.
As a temporary solution, you can use the following string

Code: Select all

  query.parambyname ('par1'). AsInteger: = Integer (somebooleanvariable);
instead of

Code: Select all

  query.parambyname ('par1').asboolean := somebooleanvariable;

helste
Posts: 6
Joined: Wed 21 Sep 2016 14:02

Re: Problem with boolean parameter in FB3

Post by helste » Mon 04 Mar 2019 15:09

Thanks for the quick reply.

The problem ist, that I use a char(1) as boolean and that contains 'T' or 'F'.

In the stored procedure I use something like that:

if (:par1 = 'T') then
.......

So when I use
query.parambyname ('par1'). AsInteger: = Integer (somebooleanvariable);

I think it would not deliver 'T' or 'F' but 1 and 0 to the stored procedure.

So have to use asstring and pas 'T' or 'F' to it, depending on somebooleanvariable is true or false.

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

Re: Problem with boolean parameter in FB3

Post by ViktorV » Thu 07 Mar 2019 12:15

We have answered you via e-mail.

helste
Posts: 6
Joined: Wed 21 Sep 2016 14:02

Re: Problem with boolean parameter in FB3

Post by helste » Thu 07 Mar 2019 12:19

Yes, thank you. I am working on an example. Will take some time, but I hope I will have it ready in the next few days.

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

Re: Problem with boolean parameter in FB3

Post by ViktorV » Wed 13 Mar 2019 11:39

Thank you for the interest to our product.
If you have any questions during using our products, please don't hesitate to contact us - and we will try to help you solve them.

Post Reply