Re: Building a tree recursively
Posted in 1998
This is a multi-part message in MIME format.
--------------CB15BB1AD6D7FF0F18F5BD13
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Scott:
You could use a prepared cursor, I mean
LET sqlstmt= "select child_no from unit_link where parent_no = ?"
PREPARE ex_sql FROM sqlstmt
DECLARE child CURSOR FOR ex_sql
then you just use OPEN USING, without need to close-reopen the cursor.
Anyway, this won't produce what you want, since the cursor are not
recursive. So, I have done this using an array in INFORMIX-4GL for store the
children records.
Scott Black wrote:
> I know someone out there must have done this before...
>
> I have a table:
> unit_link(
> parent_no integer,
> child_no integer...
>
> Each child can have children of it's own, for as many levels as
> necessary. I tried to build a recursive function call to build the tree
> as follows:
>
> function get_children(unit_no)
>
> declare child cursor for
> select child_no
> from unit_link
> where parent_no = unit_no>
> foreach child into this_unit
> call get_children(this_unit)...
>
> By now you see the problem. On the second time through I get error -400
> (Fetch attempted on unopen cursor). Tech support says that this is the
> way it is designed, you cannot re-use a cursor without first closing it.
> It seems to me that each recursive call should be within it's own stack
> and that re-using variables, cursors and the like should not be a
> problem, but...
>
> Is there another way to go about this w/o recursion? What methods have
> any of you used to solve similar problems?
>
> TIA
> BTW this is HP-UX 10.20 OnLine 7.22 4GL 6.04
--------------CB15BB1AD6D7FF0F18F5BD13
Content-Type: text/x-vcard; charset=us-ascii; name="vcard.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Melvin Perez
Content-Disposition: attachment; filename="vcard.vcf"
begin: vcard
fn: Melvin Perez
n: Perez;Melvin
org: CAM Informatica. S. A.
email;internet: cam@codetel.net.do
title: Technical Vicepresident
tel;work: (809) 686-5574
tel;fax: (809) 686-5467
tel;home: (809) 227-2893
x-mozilla-cpt: ;-960
x-mozilla-html: FALSE
version: 2.1
end: vcard
--------------CB15BB1AD6D7FF0F18F5BD13--