4GL/Engine: FETCH RELATIVE acting flakey
Posted in 1997
Hi family, I am having a flaky problem with the FETCH command. I am writing a classical menu-driven program, with QUERY, NEXT, PREVIOUS menu items. When the user calls for QUERY, I initiate the SELECT, declare a cursor and issue the FETCH FIRST command. When the user presses "NEXT", I issue the command: FETCH RELATIVE nn cursor_name. Here is a code snippet: function fetch_libdoc(nfetch) define nfetch smallint define nparm smallint # Parameter counter if nfetch = 0 then fetch first libdoc_pk_curs # Effective fetch first into rp_libdoc.funcname else fetch relative nfetch libdoc_pk_curs # Skip to current + into rp_libdoc.funcname # nfetch rows end if Problem: The first time I issue the FETCH RELATIVE command, it retrieves the first row of the query all over again! A "select count" retrieves 2 yet I can successfully run a total of 3 fetches. The form comes up with [document 3 of 2], clearly ridiculous. Answers I have eliminated: - nfetch is 0 or null No, I have repeatedly checked this in the debugger before the fetch. - I have closed the cursor and reopened it somewhere. Not possible; it would have aborted the next time I did a fetch. Just in case, I just grep'ed for the cursor name. My code has not closed the cursor anywhere. - The first row of data is really duplicated No, I ran SQL on the query. Exactly 2 rows in the active set. I have also tried using an unqualified FETCH and FETCH ABSOLUTE 1 for my initial fetch command. The problem persists! Thinking I have found a silly bug, I wrote a small test program to demonstrate the problem. SURPRISE! I could not replicate it! My tester issues FETCH FIRST followed by a loop of FETCH RELATIVE. All data was retrieved as appropriate. OK, I've eliminated the obvious. What could I possibly be overlooking? I need a brainstorming session! Thanks for any help. -- -- Jake (With a talent for finding showstoppers) . . _..-'( )`-.._ ./'. '||\\\\. }\\_/{ .//||` .`\\. ./'.|'.'||||\\\\|.. )o o( ..|//||||`.`|.`\\. ./'..|'.|| |||||\\`````` \\,@,/ ''''''/||||| ||.`|..`\\. ./'.||'.|||| ||||||||||||. ||| .|||||||||||| ||||.`||.`\\. /'|||'.|||||| ||||||||||||{ | }|||||||||||| ||||||.`|||`\\ '.|||'.||||||| ||||||||||||{ | }|||||||||||| |||||||.`|||.` '.||| ||||||||| |/' ``\\||`` | ''||/'' `\\| ||||||||| |||.` |/' \\./' `\\./ \\!|\\ /|!/ \\./' `\\./ `\\| V V V }' `\\ /' `{ V V V \\ \\ \\ V / / / +-----------------------------------------------------------+ | Impeccable Logic: A thought process which successfully | | resists chicken bites | +-----------------------------------------------------------+