INFORMIX
Informix-ESQL/C Programmer's Manual
Chapter 14: Using Dynamic SQL
Home Contents Index Master Index New Book

Optimizing OPEN, FETCH, and CLOSE

When an ESQL/C application uses DECLARE and OPEN statements to execute a cursor, each statement involves a round trip of message requests between the application and the database server. The optimize-OPEN-FETCH-CLOSE feature (OPTOFC) reduces the number of round trips by two, as follows:

    When ESQL/C executes the OPEN statement, it does not open the cursor. Instead, it saves any input value that was supplied in the USING clause of the OPEN statement. When ESQL/C executes the initial FETCH statement, it sends this input value along with the FETCH statement. The database server opens the cursor and returns the first value in this cursor.

    When the database server reaches the last value of an open cursor, it automatically closes the cursor after it sends the last value to the client application. Therefore, ESQL/C does not need to send the CLOSE statement to the database server.

Important: ESQL/C does not send the CLOSE statement to the database server. However, if you include the CLOSE statement, no error is generated.
ODS

Restrictions on OPTOFC

With the OPTOFC feature enabled, the following restrictions exist:

    With the OPTOFC feature enabled, neither static nor dynamic cursors are freed when they are closed. Because ESQL/C does not actually send the CLOSE statement to the database server, a cursor is not implicitly freed. A subsequent OPEN and FETCH on a cursor actually opens the same cursor. Only at this time would the database server notice if the table was modified (if it was dropped, altered, or renamed), in which case it generates an error (-710).

Enabling the OPTOFC Feature

The OPTOFC environment variable enables the OPTOFC feature. You can assign the following values to the OPTOFC environment variable.

Value Description

1

This value enables the OPTOFC feature. When you specify this value, you enable the OPTOFC feature for every cursor in every thread of the application.

0

This value disables the OPTOFC feature for all threads of the application.

The default value of the OPTOFC environment variable is 0 (zero). If you set this environment variable from the shell, make sure you set it before you start the ESQL/C application.

On UNIX operating systems, you can set OPTOFC from within the application with the putenv() system call (as long as your system supports the putenv() function). For example, the following call to putenv() enables the OPTOFC feature:

WIN 95

In Windows environments, you can use the ifx_putenv() function.

With putenv() or ifx_putenv(), you can activate or deactivate the OPTOFC feature for each connection or within each thread. You must call the putenv() or ifx_putenv() function before you establish a connection.

Important: Informix utilities do not support the IFX_AUTOFREE, OPTOFC, and IFX_DEFERRED_PREPARE environment variables. Use these environment variables only with INFORMIX-ESQL/C client applications.




Informix-ESQL/C Programmer's Manual, version 9.1
Copyright © 1998, Informix Software, Inc. All rights reserved.