Problem with boolean parameter in FB3
Posted: 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?
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?