Program Termination When Errors Occur
The SET_SQL(PROGRAMQUIT) statement specifies how an embedded OpenSQL application handles the following types of errors:
• Attempting to execute a query when not connected to a database
• Enterprise Access product or DBMS server failure
• Communications service failure
By default, when these types of errors occur, OpenSQL issues an error but lets the program continue.
To force an application to abort when one of these errors occur, issue the following SET_SQL statement:
exec sql set_sql (programquit = 1);
If an application aborts as the result of one of the previously listed errors, OpenSQL issues an error, then rolls back open transactions and disconnects all open sessions. (To disable aborting and restore the OpenSQL default behavior, specify programquit = 0.)
Errors affected by the programquit setting belong to the generic error class GE_COMM_ERROR, which is returned to errorno as 37000, and to sqlcode (in the SQLCA) as ‑37000. An application can check for these errors and, when detected, must disconnect from the current session. After disconnecting from the current session, the application can attempt another connection, switch to another session (if using multiple sessions), or perform clean‑up operations and quit.
You can also specify programquit using II_EMBED_SET.
To determine the current setting for this behavior, use the INQUIRE_SQL statement:
exec sql inquire_sql (int_variable = programquit);
This returns a 0 if programquit is not set (OpenSQL continues on any of the errors) or 1 if programquit is set (OpenSQL exits the application on these errors).
Last modified date: 01/30/2023