Subject | Re: SPs and recursion |
---|---|
Author | duilio_fos <irel_llc@libero.it> |
Post date | 2003-02-20T22:06:04Z |
Nando,
The table resembles a linked list:
create table Tree
(
fm_id integer not null, /* from ID */
to id integer not null /* to ID */
)
current test data is
fm_id to_id
0 338
338 339
0 340
340 341
Data show 2 paths:
0 -> 338 -> 339
and
0 -> 340 -> 341
I want to write a SP - let's call it BackPath - that - called as
select * from BackPath(339)
will return
339
338
0
I have already solved the problem by using a temporary table with a
recursive BEFORE INSERT trigger.
Now I want to try to solve the same problem without temporary tables.
I wrote what looked a smart solution (shamelessly copied from your
code):
CREATE PROCEDURE WayBack(sol integer)
RETURNS
(result integer)
AS
BEGIN
if (:sol = 0) THEN
begin
result = 0;
suspend;
exit;
end
for select result from WayBack(:sol) into :result
do
begin
suspend;
select fm_sol from a_dep where to_sol=:result into :sol;
end
END
However, this code seems to fall into a never ending loop, as I get
the error message:
"too many concurrent executions of the same request"
What's wrong in my code and how should it be corrected ?
Thank you
Duilio
>And unneeded, too.I tried to use your code to return the descent of a record in a table.
The table resembles a linked list:
create table Tree
(
fm_id integer not null, /* from ID */
to id integer not null /* to ID */
)
current test data is
fm_id to_id
0 338
338 339
0 340
340 341
Data show 2 paths:
0 -> 338 -> 339
and
0 -> 340 -> 341
I want to write a SP - let's call it BackPath - that - called as
select * from BackPath(339)
will return
339
338
0
I have already solved the problem by using a temporary table with a
recursive BEFORE INSERT trigger.
Now I want to try to solve the same problem without temporary tables.
I wrote what looked a smart solution (shamelessly copied from your
code):
CREATE PROCEDURE WayBack(sol integer)
RETURNS
(result integer)
AS
BEGIN
if (:sol = 0) THEN
begin
result = 0;
suspend;
exit;
end
for select result from WayBack(:sol) into :result
do
begin
suspend;
select fm_sol from a_dep where to_sol=:result into :sol;
end
END
However, this code seems to fall into a never ending loop, as I get
the error message:
"too many concurrent executions of the same request"
What's wrong in my code and how should it be corrected ?
Thank you
Duilio