Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!mnetor!uunet!seismo!husc6!cmcl2!beta!hc!ames!ptsfa!bh
From: bh@ptsfa.UUCP (Brian Holliday)
Newsgroups: comp.databases
Subject: Re: Big fun w/Informix cursors.
Message-ID: <3219@ptsfa.UUCP>
Date: Thu, 9-Jul-87 17:39:03 EDT
Article-I.D.: ptsfa.3219
Posted: Thu Jul  9 17:39:03 1987
Date-Received: Sun, 12-Jul-87 07:05:23 EDT
References: <147@paisano.UUCP>
Organization: Pacific * Bell, San Ramon, CA
Lines: 59




demasi@paisano.UUCP (Michael C. De Masi) in <147@paisano.UUCP>, writes:

>Basically, what I was wondering if I had missed something regarding
>the cursor concept in Informix esql/c.  The first question involves
>the use of the 'fetch' statement to advance the cursor through a
>queried list of rows from a given declare statement.  Although fetch
>does a fine job in the forward direction, there seems to be no way to
>do what I would imagine would best be called an 'unfetch'.  Ie, is it
>possible to back the cursor up a row (or more) to traverse already
>fetched data? It would certainly seem to be a nice thing to be able to do,
>and in fact is quite possible from the vanilla Informix generated screens.

>The second question involves active lists queried down for update
>purposes.  Again, one might query the set and advance through it
>with fetch statements, but it seems that the first non-readonly activity
>performed after the query (ie an insert, deletion or update) somehow
>breaks the cursor making it impossible to use for any purpose.
>Now maybe I can buy the fact that these cursors were meant to be
>uni-directional, but am I to understand that they were designed to
>be as fragile as I've stated?  Why bother to make it possible to
>query multiple records for update when making one change to one 
>record makes the whole query inoperative?

I have not used Informix ESQL/C -- but I am a current user of Informix 4GL.
Informix 4GL programs are compiled down into ESQL/C, so if a 4GL solution is
satisfactory, you should be able to do the same thing in ESQL/C.  (You will
just need to write more code.)

You are correct -- cursors take you forward through your database
selections, and there is no way to step backwards, and ask for a previously
fetched selection.  I used vanilla Informix 3.3 before I used Informix 4GL,
so this apparent brain damage affected me in the same manner it has affected
you ([insert favorite 4-letter word here]!).  However, now that I know 4GL
much better, I immensely prefer it over the vanilla Informix.   Since 4GL
programming is so much easier and more productive than vanilla Informix, I
accept the work-around.

Declare two cursors -- one that goes forward (let's call it CURSORF),
and one that goes backwards (let's call it CURSORB).  Both cursors use the
data from the current cursor, and find the next data (there's a ">"
selection) or previous data (a "<" selection).

To go forward: OPEN CURSORF, FETCH CURSORF, and CLOSE CURSORF.
To go backwards: OPEN CURSORB, FETCH CURSORB, and CLOSE CURSORB.

Since the cursor has been closed, your second question/problem has also been
solved.  You may update/delete/whatever, and then open up the cursor
for the next selection.

As 4GL technology improves, these goofy things will be ironed out.
I'm looking forward to better 4GLs, and the upcoming 5GLs in the 1990's.

<>

Brian Holliday (...!ptsfa!bh)