Issue Details (XML | Word | Printable)

Key: CORE-1716
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Adriano dos Santos Fernandes
Reporter: Viner Mihail
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Firebird Core

Wrong variable initialization in recursive procedures

Created: 30/Jan/08 09:48 AM   Updated: 18/Nov/08 01:40 PM
Component/s: Engine
Affects Version/s: 2.1 RC1
Fix Version/s: 2.1 RC2

Time Tracking:
Not Specified

Environment: WinXP

Planning Status: Unspecified


 Description  « Hide
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

 All   Comments   Work Log   Change History   Version Control   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Adriano dos Santos Fernandes added a comment - 30/Jan/08 02:09 PM
Please test the fix in a next snapshot.