Open a cursor
The program opens the cursor when it is ready to use it.
The OPEN statement activates the cursor. It passes the associated
SELECT statement to the database server, which begins the search for
matching rows. The database server processes the query to the point
of locating or constructing the first row of output. It does not actually
return that row of data, but it does set a return code in SQLSTATE
and in SQLCODE for SQL APIs. The following example shows the OPEN
statement in Informix®
ESQL/C:
EXEC SQL OPEN the_item;
Because
the database server is seeing the query for the first time, it might
detect a number of errors. After the program opens the cursor, it
should test SQLSTATE or SQLCODE. If the SQLSTATE value is greater
than 02000
or the SQLCODE contains a negative number,
the cursor is not usable. An error might be present in the SELECT
statement, or some other problem might prevent the database server
from executing the statement.
If SQLSTATE is equal to 00000
,
or SQLCODE contains a zero, the SELECT statement is syntactically
valid, and the cursor is ready to use. At this point, however, the
program does not know if the cursor can produce any rows.