SQL/MX Programming Manual for C and COBOL (G06.24+, H06.03+)
Exception Handling and Error Conditions
HP NonStop SQL/MX Programming Manual for C and COBOL—523627-004
13-16
Occurrences of the Lost Open Error
operation invalidates the open held by the program to change the structure of the table
or view and gains exclusive access to the table or view. A program could also lose its
open on a table or view when a network or hardware interruption occurs.
Occurrences of the Lost Open Error
If a DML statement partially modifies a database object (that is, table, view, and so on)
before the open is invalidated, the SQL/MX executor rolls back the changes made by
the statement and returns the Lost Open Error (8574) to the program. For example,
consider an INSERT statement on a table that has an index. The INSERT statement
always modifies the table first before updating the index. If the index is destroyed, the
Lost Open Error occurs.
If a cursor returns one or more rows to the program before the open is invalidated, the
SQL/MX executor returns the Lost Open Error (8574) to the program. If a cursor or
DML statement does not return any rows to the program before the open is invalidated,
the SQL/MX executor retries the cursor or DML statement and then waits for the lock
to be released on the table or view. If the lock is not released before the timeout is
reached, the SQL/MX executor returns the Lost Open Error (8574) to the program.
If the lock is released before the timeout is reached, the SQL/MX executor reopens the
table or view. If reopening the table or view results in a timestamp mismatch, the
SQL/MX executor performs a similarity check of the table or view. If the similarity check
fails (or is disabled), the SQL/MX executor tries to automatically recompile the
statement. If the SQL/MX executor cannot recompile the statement, it returns the Lost
Open Error (8574), as well as other recompilation errors, to the program. For more
information on similarity checks and automatic recompilation, see Section 8, Name
Resolution, Similarity Checks, and Automatic Recompilation.
Recovering From the Lost Open Error
If DML or cursor operations in a program enable concurrent access to tables or views,
or if you anticipate network or hardware interruptions, add code to the program to catch
and handle the Lost Open Error (8574). The way that you handle occurrences of the
Lost Open Error (8574) depends on what you are trying to accomplish with the DML
statement or cursor. In most cases, when the Lost Open Error (8574) occurs, the
program should retry the DML statement or close and reopen the cursor before
executing a subsequent FETCH statement.
This example provides general error recovery code:
void sql_error(void)
{
if (SQLCODE == -8574)
{
printf("Recovering cursor from error %ld\n", SQLCODE);
EXEC SQL Open C1;
}
}