Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 1 of 1 total
Thread Recursive Functions
Mon, Jun 28 2010 6:38 PMPermanent Link

Richard Harding

Wise Nutrition Coaching

Tim,

I upgraded to v2.03b15 and tested out recursive functions with the following which works.

CREATE FUNCTION "TriangleNumber" (IN "N" INTEGER)
RETURNS INTEGER
BEGIN   
 DECLARE Result, I INTEGER;
 
 SET I = N;     -- Required
 CASE I
   WHEN 0 THEN
     SET Result = 0;
   WHEN 1 THEN
     SET result = 1;
   ELSE
     SET Result = I + TriangleNumber(I - 1);
 END CASE;
  
 RETURN Result;
END

However, if the line SET I = N is removed and the subsequent references to I are replaced by the parameter N then EDBMgr terminates.

Also, on the second execution of the function from EDBMgr, the input parameter dialog shows the parameter N as being a VARCHAR.

Tried to calculate fibonacci numbers with the following function and it crashes with AV if the parameter is 5 or greater.

CREATE FUNCTION "R" (IN "I" INTEGER)
RETURNS INTEGER
BEGIN   
 DECLARE Result, N, M INTEGER;
 
 SET N = I-1;     
 SET M = i-2;       

 CASE N
   WHEN 0 THEN
     SET Result = 0;
   WHEN 1 THEN
     SET result = 1;
   ELSE
     SET Result = R(N) + R(M);
 END CASE;
  
 RETURN Result;
END

Richard Harding
Image