>Message-Id: <9204272215.AA15947@rmy.rmy.emory.edu>
>From: uunet!green.att.com!chris (Chris Hardin)
>Date: Mon, 27 Apr 92 18:11 EDT
>Subject: What is error -424 in ESQL/C
>X-Informix-List-Id: <list.1106>
>
>Error message -424: Cursor already declared from this prepared statement.
>(It's not listed the error message appendix)
It is listed in the Version 5.00 Error Message manual.
>< User enters non-scrolling select statement >
> [ $PREPARE query_object from $query_statement ]
> [ $DESCRIBE query_object INTO description ]
> [ $DECLARE my_cursor CURSOR FOR query_object ]
> [ $OPEN my_cursor ]
> [ $FETCH, parse sqlda, and display rows (in a loop) ]
> [ $CLOSE my_cursor ]
> [ $FREE query_object ]
>< User enters scrolling select statement >
> [ $PREPARE query_object from $query_statement ]
> [ $DESCRIBE query_object INTO description ]
> [ $DECLARE my_cursor SCROLL CURSOR FOR select_statement ]
> [ error -424 ]
>The environment: INFORMIX-SE Version 4.00.UH1
>First of all, could someone explain the error message.
The 5.00 manual says, by way of explanation:
This DECLARE statement associates a cursor with the name of a prepared
statement. However, another DECLARE statement has already been executed,
associating a different cursor with the same statement ID. This is not
supported; a given statement may be associated with only one cursor. Check
all the DECLARE statements in the program and make sure they all refer to
unique statements.
The reason behind this (not in the book of words) is that when you FREE
something, if it is a cursor declared on a prepared statement, you free the
statement id, not the cursor id. If, instead, you said "DECLARE c CURSOR
FOR SELECT ...", then (and only then) would you free the cursor name. And
if two cursors were allowed on one statement id, then freeing the first
cursor would wreck the second. Note that I am merely stating why; I am not
actually justifying it (because it would not be all that hard to keep a
reference count for the statement id and only release the statement when
the reference count drops to zero).
Yours sincerely,
Jonathan Leffler (johnl@obelix.informix.com)