Re: Return values ???
Posted in 1999
Oops, sory. I think this form has apeared in 4GL v7.x. I'm working with 6.x and I don't have this syntax yet :-) Best Regards, Octav On Tue, Aug 10, 1999 at 02:43:02PM +0200, Mark Secher Paludan wrote: > You can pass parameters with FOREACH: > > FOREACH qCursorName USING var1, var2 INTO result1, result2 > DO SOMETHING > END FOREACH > > Octav Chiriac wrote<7op54c$pgr$1@news.xmission.com>... > > > >In fact I think there are no so big diference. FOREACH as I understand > >does the same steps as the programmer when he writes OPEN .. WHILE .. > >check for NOTDOUND. > >But, Jonathan, we can't pass any parameters to procedure > >with FOREACH. > > > >Best Regards, > >Octav > > > >On Tue, Aug 10, 1999 at 07:11:58AM -0400, Barnes, Steve (IFMG) wrote: > >> Jonathan, > >> > >> I am curious as to why a FOREACH is considered better than OPEN, WHILE, > >> FETCH, CLOSE. I always thought that for large numbers of reads, the > overhead > >> of a FOREACH instead of the alternative had performance impacts. This was > >> the thought a few years ago, and maybe I am behind the times! > >> > >> Can you please clarify this for me please. > >> > >> Thanks > >> > >> Steve > >> > >> -----Original Message----- > >> From: Jonathan Leffler [mailto:jleffler@earthlink.net] > >> Sent: Monday, August 09, 1999 11:59 PM > >> To: informix-list@iiug.org > >> Subject: Re: Return values ??? > >> > >> Octav Chiriac wrote: > >> > [...various variations on PREPARE and DECLARE...] > >> > OPEN qCursorName USING var1, var2 > >> > > >> > WHILE TRUE > >> > FETCH qCursorName INTO result1, result2 > >> > IF sqlca.sqlcode == NOTFOUND THEN > >> > EXIT WHILE > >> > END IF > >> > > >> > -- DO SOMETHING WITH YOUR results > >> > > >> > END WHILE > >> > > >> > CLOSE qCursorName > >> > > >> > FREE ... stuff > >> > >> It is much better to use a FOREACH loop because it is more > >> reliable: > >> > >> PREPARE p_stmt FROM "EXECUTE PROCEDURE theprocedure(?,?)" > >> DECLARE c_stmt FROM p_stmt > >> > >> FOREACH c_stmt USING var1, var2 INTO result1, result2 > >> ...Do Something With Your Results... > >> END FOREACH > >> > >> FREE c_stmt > >> FREE p_stmt > >> > >> Don't forget to release both the statement and the cursor. > >> And > >> do use FOREACH rather than ever writing out the loop from > >> spare > >> parts (OPEN, WHILE, FETCH, CLOSE). > >> > >> This has been available since at latest the 4.14/6.02 > >> release pair, > >> and possibly as early as the 4.12/6.00 release pair. > >> > >> -- > >> Jonathan Leffler (jleffler@informix.com, > >> jleffler@earthlink.net) > >> Guardian of DBD::Informix v0.60 -- see > >> http://www.perl.com/CPAN > >> #include <disclaimer.h> > > > >-- > >Octav Chiriac Phone: (373) 2 22 99 67 > >NetInfo S.R.L. Fax: (373) 2 21 36 59 > >Chisinau (373) 2 22 84 88 > >Moldova, Republic of mailto:com@netinfo-moldova.com > -- Octav Chiriac Phone: (373) 2 22 99 67 NetInfo S.R.L. Fax: (373) 2 21 36 59 Chisinau (373) 2 22 84 88 Moldova, Republic of mailto:com@netinfo-moldova.com