Re: Foreach statement
Posted in 1997
Jacob Salomon <jake@apparel.net> wrote: >Since the FOREACH is [allegedly] the equivalant of an OPEN, the FOREACH >should be close the cursor and reopen it, just as an explicit OPEN would >do. You are correct; the FOREACH has been behaving this way. It used to work like that, once upon a long time ago, in some older versions of I4GL (and ESQL/C). I don't think that the list of 'older versions' includes the 4.12 ESQL/C that comes with the 4.12 and later 4.1x versions of I4GL; it definitely does not include any 6.0x version of I4GL. >However, this is incorrect behavior for the FOREACH. Yes, it was incorrect behaviour. More strictly, it was incorrect for the OPEN to remember the USING values from the previous use when no new values were supplied when the cursor was re-opened. >I found this code all over the place at my place and was quite >annoyed at this abuse of what is really a bug (IMO). Mine, too. And Informix's. >I reported it to Informix as such. One of these days, some >well-meaning purist will fix this bug (I wonder if this works in ESQL >also) and break an awful lotta code out there. It has been fixed. Some I4GL code has been broken by it, and fixed. The best answer is to use: FOREACH c_cursor USING varlist1 INTO varlist2 This should have been in the product with release 1.0, but it got there eventually. >Then I'll be gloating: "See? I told you so!" ;-) You may commence gloating, though you're a few years late starting. It's been fixed like that for quite a while. >Jim Young wrote: >> Undocumented feature: >> >> For the older versions, you can do an open using statement, then do >> your foreach statement without a using clause - it works just like >> you had a using clause on the foreach. Do not use this feature -- it will cause more problems than it solves. >> Denis Cloutier wrote: >> >> > I was at the Informix conference a couple of weeks ago and >> > went to the 4gl-Tips and Tricks track. At that seminar, I >> > could swear I heard someone mention that a "using" clause >> > could be used with a foreach statement now. Is this true? Yours, Jonathan Leffler (johnl@informix.com) #include <disclaimer.h> PS: Warning I do not reply to messages with anti-spam in the return path.