Help needed: Using LIST-Elements
Posted in 2000
Topics: Stored Procedures & SPL, Versions, Editions & End-of-Life
Hi,
can anyone tell me how to use LIST collections. I'm using IDS 9.14.UC6.
I need to use nested LIST collections realy hard, so say are used as
function parameters and as variables in UDR, too.
I've some problems in using nested List collections. Does anyone know
how to use them correct in UDR-routines?
How do I handle nested List collections as function parameter and how
can I retreive nested List collection from
a function into an other variable in a UDR that calls the function?
I know that my UDR is quit long, so excuse me that long listing.
Please if anyone has some advice I would be very pleased, because it's
very important to me.
Thanks in advance.
Rgds,
Peter.
Example:
CREATE FUNCTION extensions(paths LIST(LIST(INT NOT NULL) NOT NULL),
length INT, filter INT)
RETURNING LIST ( LIST (INT NOT NULL) NOT NULL);
DEFINE extensions LIST ( LIST (INT NOT NULL) NOT NULL);
DEFINE candidates LIST ( LIST (INT NOT NULL) NOT NULL);
DEFINE ext_elm LIST (INT NOT NULL);
DEFINE cand_elm LIST (INT NOT NULL);
DEFINE ext_oid INT;
DEFINE cand_oid INT;
DEFINE cand_length INT;
DEFINE neigh_oid INT;
DEFINE card_cand INT;
DEFINE n INT;
TRACE ON;
SELECT * INTO candidates FROM TABLE(paths);
LET card_cand = CARDINALITY(candidates);
LET extensions = LIST{}::LIST(LIST(INT NOT NULL)NOT NULL);
WHILE card_cand > 0
BEGIN
DELETE FROM TABLE(cand_elm); FOREACH cursor1 FOR
SELECT * INTO cand_elm FROM TABLE(candidates)
DELETE FROM TABLE(candidates)
WHERE CURRENT OF cursor1; EXIT FOREACH;
END FOREACH;
LET cand_length = CARDINALITY(cand_elm);
IF cand_length < length THEN
BEGIN
LET n = 0;
FOREACH cursor2 FOR
SELECT * INTO cand_oid FROM TABLE(cand_elm)
LET n = n + 1; IF n < cand_length THEN
CONTINUE FOREACH;
END IF;
END FOREACH;
LET ext_elm = cand_elm;
FOREACH EXECUTE FUNCTION n_gem_dist10_ix(cand_oid) INTO neigh_oid
BEGIN
FOREACH cursor3 FOR
SELECT * INTO ext_oid FROM TABLE(ext_elm)
if neigh_oid = ext_oid THEN
EXIT FOREACH; END IF;
INSERT INTO TABLE(ext_elm) VALUES(neigh_oid);
INSERT AT 1 INTO TABLE(candidates) VALUES(ext_elm);
END FOREACH;
END
END FOREACH;
END
ELIF cand_length = length THEN
INSERT INTO TABLE(extensions) VALUES(ext_elm); END IF;
LET card_cand = CARDINALITY(candidates);
END
END WHILE;
RETURN extensions;
END FUNCTION;
>Subject: Help needed: Using LIST-Elements
>From: Peter Hamm hamm@dbs.informatik.uni-muenchen.de
>Date: 17.04.00 17:02 W. Europe Daylight Time
>Message-id: <38FB277F.38DA4B02@dbs.informatik.uni-muenchen.de>
>
>This is a multi-part message in MIME format.
>--------------3B87FF7D887B421FE9767265
>Content-Type: text/plain; charset=us-ascii
>Content-Transfer-Encoding: 7bit
>
>Hi,
>
>can anyone tell me how to use LIST collections. I'm using IDS 9.14.UC6.
>
>I need to use nested LIST collections realy hard, so say are used as
>function parameters and as variables in UDR, too.
>I've some problems in using nested List collections. Does anyone know
>how to use them correct in UDR-routines?
>How do I handle nested List collections as function parameter and how
>can I retreive nested List collection from
>a function into an other variable in a UDR that calls the function?
>
>I know that my UDR is quit long, so excuse me that long listing.
>Please if anyone has some advice I would be very pleased, because it's
>very important to me.
>
>Thanks in advance.
>
>Rgds,
>Peter.
>
>
>Example:
>
>CREATE FUNCTION extensions(paths LIST(LIST(INT NOT NULL) NOT NULL),
>length INT, filter INT)
>RETURNING LIST ( LIST (INT NOT NULL) NOT NULL);>
>DEFINE extensions LIST ( LIST (INT NOT NULL) NOT NULL);
>DEFINE candidates LIST ( LIST (INT NOT NULL) NOT NULL);
>DEFINE ext_elm LIST (INT NOT NULL);
>DEFINE cand_elm LIST (INT NOT NULL);
>DEFINE ext_oid INT;
>DEFINE cand_oid INT;
>DEFINE cand_length INT;
>DEFINE neigh_oid INT;
>DEFINE card_cand INT;
>DEFINE n INT;
>
>TRACE ON;
>
>SELECT * INTO candidates FROM TABLE(paths);>
>LET card_cand = CARDINALITY(candidates);
>LET extensions = LIST{}::LIST(LIST(INT NOT NULL)NOT NULL);
>
>WHILE card_cand > 0
>
> BEGIN
>
> DELETE FROM TABLE(cand_elm);> FOREACH cursor1 FOR
> SELECT * INTO cand_elm FROM TABLE(candidates)
> DELETE FROM TABLE(candidates)
> WHERE CURRENT OF cursor1;> EXIT FOREACH;
> END FOREACH;
>
> LET cand_length = CARDINALITY(cand_elm);
> IF cand_length < length THEN
> BEGIN
> LET n = 0;
> FOREACH cursor2 FOR
> SELECT * INTO cand_oid FROM TABLE(cand_elm)
> LET n = n + 1;> IF n < cand_length THEN
> CONTINUE FOREACH;
> END IF;
> END FOREACH;
>
> LET ext_elm = cand_elm;
>
> FOREACH EXECUTE FUNCTION n_gem_dist10_ix(cand_oid) INTO neigh_oid
> BEGIN
> FOREACH cursor3 FOR
> SELECT * INTO ext_oid FROM TABLE(ext_elm)
> if neigh_oid = ext_oid THEN
> EXIT FOREACH;> END IF;
> INSERT INTO TABLE(ext_elm) VALUES(neigh_oid);>
> INSERT AT 1 INTO TABLE(candidates) VALUES(ext_elm);
> END FOREACH;
> END
> END FOREACH;
> END
> ELIF cand_length = length THEN
> INSERT INTO TABLE(extensions) VALUES(ext_elm);> END IF;
> LET card_cand = CARDINALITY(candidates);
> END
>END WHILE;
>
>RETURN extensions;
>END FUNCTION;
>
>
>--------------3B87FF7D887B421FE9767265
>Content-Type: text/x-vcard; charset=us-ascii;
> name="hamm.vcf"
>Content-Transfer-Encoding: 7bit
>Content-Description: Card for Peter Hamm
>Content-Disposition: attachment;
> filename="hamm.vcf"
>
>begin:vcard
>n:Hamm;Peter
>tel;cell:+49 171 / 8 98 48 00
>tel;fax:+49 89 / 48 00 24 21
>tel;home:+49 89 / 48 00 24 20
>x-mozilla-html:TRUE
>org:University of Munich;Computer Science
>adr:;;Comeniusstrasse 3 / Rgb;Munich;Bavaria;81667;Germany
>version:2.1
>email;internet:hamm@dbs.informatik.uni-muenchen.de
>x-mozilla-cpt:;2336
>fn:Peter Hamm
>end:vcard
>
>--------------3B87FF7D887B421FE9767265--
>
>
for one, you should be working with 9.20. And stored procedures is really not
the right way to go about tackling LISTs. Try esql/c after you move to 9.2.
Nona
Peter Hamm wrote: > can anyone tell me how to use LIST collections. I'm using IDS 9.14.UC6. You're probably best off by upgrading to 9.2. There were a set of bugs and problems with COLLECTIONS in 9.14. Most of them have been cleaned up in 9.2.