Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Firebird 5: (var)char variables/parameters assignments fail in Stored Procedures with subroutines #8063

Closed
martijntonies opened this issue Apr 2, 2024 · 0 comments

Comments

@martijntonies
Copy link

Take this procedure, connect with SYSDBA.

SET TERM ^^ ;
CREATE OR ALTER PROCEDURE P_2
returns (
O_CHAR VarChar(200) character set utf8)
SQL SECURITY INVOKER
AS
declare variable i integer;
declare variable a integer;
declare variable o integer;
declare variable outer_v varchar(200) character set utf8;

declare function m (v varchar(10)) returns varchar(10) as
begin
return v || outer_v;
end

declare function myfunc (a2 integer) returns integer as
declare variable inner_char varchar(200);
begin
i = i + 1;
select current_user from rdb$database where current_user = 'SYSDBA' into :outer_v;
inner_char = m('test');
if (a2 = 4)
then a2 = myfunc(a2 + 1);
return a2 * :a * :i;
end

begin
/* i = 5;
i = package_test.MyFunction(2);
i = mult(4, 2);
o = myfunc(a);*/
outer_v = current_user;
o_char = outer_v;
end ^^
SET TERM ; ^^

When executing, it returns “S” for output parameter O_CHAR.

Now, recreate the procedure, but comments out the “declare functions”:

SET TERM ^^ ;
CREATE OR ALTER PROCEDURE P_2
returns (
O_CHAR VarChar(200) character set utf8)
SQL SECURITY INVOKER
AS
declare variable i integer;
declare variable a integer;
declare variable o integer;
declare variable outer_v varchar(200) character set utf8;

/* declare function m (v varchar(10)) returns varchar(10) as
begin
return v || outer_v;
end

declare function myfunc (a2 integer) returns integer as
declare variable inner_char varchar(200);
begin
i = i + 1;
select current_user from rdb$database where current_user = 'SYSDBA' into :outer_v;
inner_char = m('test');
if (a2 = 4)
then a2 = myfunc(a2 + 1);
return a2 * :a * :i;
end */

begin
/* i = 5;
i = package_test.MyFunction(2);
i = mult(4, 2);
o = myfunc(a);*/
outer_v = current_user;
o_char = outer_v;
end ^^
SET TERM ; ^^

execute again: the routine returns “SYSDBA”.

The lines executed are no different, but the result is now correct. At first I thought it had something to do with the character set, so I added the UTF8 thing everywhere, even though thats the default character set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment