Subject | Re: [ib-support] "Unknown error" during procedure execute... |
---|---|
Author | Lucas Franzen |
Post date | 2001-07-15T21:43:10Z |
Roman,
I guess you used the SUSPEND within a procedure to bypass the IB-bug.
Maybe it would help to use:
IF (NOT temp IS NULL) THEN BEGIN
IF (temp > 0) THEN
SELECT RESULT FROM factorial(:temp) INTO :temp;
instead of:
IF (NOT temp IS NULL) THEN BEGIN
IF (temp > 0) THEN
EXECUTE PROCEDURE factorial(:temp) RETURNING_VALUES :temp;
Be aware that you can only pass values up to 12 (with IB5.6 or IB6,
dialect 1) or up to 20 (IB 6 dialect 3) to this procedure since
otherwise the result won't fit into an integer...
And if it's about a factorial proecure wouldn't it be easier to do:
CREATE PROCEDURE FACTORIAL (NUMBER INTEGER)
RETURNS (RESULT INTEGER)
AS
DECLARE VARIABLE temp INTEGER;
BEGIN
RESULT = -1; /* or whatever to indicate a improper input param)
IF ( NUMBER IS NOT NULL AND NUMBER > 0 AND NUMBER < 20 ) THEN
BEGIN
temp = number - 1;
RESULT = number;
WHILE ( TEMP > 1 ) DO
BEGIN
RESULT = RESULT * TEMP;
TEMP = TEMP - 1;
END
END
SUSPEND;
END
Regards
Luc.
RRokytskyy@... schrieb:
I guess you used the SUSPEND within a procedure to bypass the IB-bug.
Maybe it would help to use:
IF (NOT temp IS NULL) THEN BEGIN
IF (temp > 0) THEN
SELECT RESULT FROM factorial(:temp) INTO :temp;
instead of:
IF (NOT temp IS NULL) THEN BEGIN
IF (temp > 0) THEN
EXECUTE PROCEDURE factorial(:temp) RETURNING_VALUES :temp;
Be aware that you can only pass values up to 12 (with IB5.6 or IB6,
dialect 1) or up to 20 (IB 6 dialect 3) to this procedure since
otherwise the result won't fit into an integer...
And if it's about a factorial proecure wouldn't it be easier to do:
CREATE PROCEDURE FACTORIAL (NUMBER INTEGER)
RETURNS (RESULT INTEGER)
AS
DECLARE VARIABLE temp INTEGER;
BEGIN
RESULT = -1; /* or whatever to indicate a improper input param)
IF ( NUMBER IS NOT NULL AND NUMBER > 0 AND NUMBER < 20 ) THEN
BEGIN
temp = number - 1;
RESULT = number;
WHILE ( TEMP > 1 ) DO
BEGIN
RESULT = RESULT * TEMP;
TEMP = TEMP - 1;
END
END
SUSPEND;
END
Regards
Luc.
RRokytskyy@... schrieb:
>
> Hello,
>
> Maybe I'm in wrong list, so please point the right one. :)
>
> I have strange behaviour of Firebird 0.9.4p1/Win2k and with IB
> 6.0.1/Win2k during procedure execute.
>
> Procedure code:
>
> SET TERM ^ ;
>
> /* Stored procedures */
>
> CREATE PROCEDURE FACTORIAL (NUMBER INTEGER)
> RETURNS (RESULT INTEGER)
> AS
> BEGIN EXIT; END ^
>
> ALTER PROCEDURE FACTORIAL (NUMBER INTEGER)
> RETURNS (RESULT INTEGER)
> AS
> DECLARE VARIABLE temp INTEGER;
> BEGIN
> temp = number - 1;
> IF (NOT temp IS NULL) THEN BEGIN
> IF (temp > 0) THEN
> EXECUTE PROCEDURE factorial(:temp) RETURNING_VALUES :temp;
> ELSE
> temp = 1;
> result = number * temp;
> END
>
> SUSPEND;
> END
> ^
>
> SET TERM ; ^
>
> Simple enough (at least I think so :))
>
> Statement
>
> SELECT * FROM factorial(5);
>
> executed in ISQL produces error "Unknown error Statement: select *
> from factorial(5)" but after pressing "OK" button produces the
> result "120".
>
> Statement
>
> EXECUTE PROCEDURE factorial(5);
>
> executes in ISQL without any problem and produces the result "<null>".
>
> The questions are:
>
> - what kind of behaviour should I expect from this simple procedure?
>
> - are there any issues with the recursive procedure calls?
>
> Thanks in advance,
> Roman Rokytskyy
>
>
> To unsubscribe from this group, send an email to:
> ib-support-unsubscribe@egroups.com
>
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/