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

Wrong variable initialization in recursive procedures [CORE1716] #2141

Closed
firebird-automations opened this issue Jan 30, 2008 · 6 comments
Closed

Comments

@firebird-automations
Copy link
Collaborator

Submitted by: Viner Mihail (mviner)

1) Create not-null domain with specified default value (the type doesn't matter: varchar, integer, ...):
create domain intdef$ as integer default 0 not null

2) Create recursive procedure with variable of not-null domain either local or returned:

-- sample with returned variable
create procedure a(cnt integer)
returns (ret intdef$)
as
begin
-- ret = 0;
while (cnt>0) do begin
cnt = cnt-1;
for select ret from a(:cnt) into ret do suspend;
end
suspend;
end

or

-- sample with local variable
create procedure a(cnt integer)
returns (ret intdef$)
as
declare x intdef$;
begin
-- x = 0;
while (cnt>0) do begin
cnt = cnt-1;
for select ret from a(:cnt) into ret do begin ret=x; suspend; end
end
ret=x;
suspend;
end

3) Call the procedure:
select * from a(4)
It fails with: The insert failed because a column definition includes validation constraints. Validation error for variable RET, value '*** null ***'.

4) When assignments of variables (ret = 0 and x = 0 respectively) are uncommented, both procedures work properly returning 16 zeros.
Seems like variables in procedures called recursively don't get their initial values from their domains and remain nulls. This is unlike any other variable (declared in non-recursive procedures). For example, this procedure normally returns zero:

create procedure a(cnt integer)
returns (ret intdef$)
as
begin
suspend;
end

Commits: e3cdddf 06328e6

@firebird-automations
Copy link
Collaborator Author

Modified by: @asfernandes

assignee: Adriano dos Santos Fernandes [ asfernandes ]

@firebird-automations
Copy link
Collaborator Author

Commented by: @asfernandes

Please test the fix in a next snapshot.

@firebird-automations
Copy link
Collaborator Author

Modified by: @dyemanov

Fix Version: 2.1 RC2 [ 10250 ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @dyemanov

status: Open [ 1 ] => Resolved [ 5 ]

resolution: Fixed [ 1 ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @pcisar

status: Resolved [ 5 ] => Closed [ 6 ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @pavel-zotov

status: Closed [ 6 ] => Closed [ 6 ]

QA Status: Done successfully

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

No branches or pull requests

2 participants