Exception handling with the sqlca structure
An alternative way to obtain diagnostic information is through the SQL Communications Area. When an SQL statement executes, the database server automatically returns information about the success or failure of the statement in a C structure that is called sqlca.
To obtain exception information, your program
can access the sqlca structure or the SQLCODE variable
as follows:
- The sqlca structure. You can use C statements to obtain additional exception information. You can also obtain information relevant to performance or the nature of the data that is handled. For some statements, the sqlca structure contains warnings.
- The SQLCODE variable directly. You can obtain the status code of the most-recently executed SQL statement. SQLCODE holds an error code that is specific to HCL OneDB™, which is copied from the sqlca.sqlcode field.
Important: supports
the sqlca structure for compatibility with earlier versions.
It is recommended, however, that new applications use the SQLSTATE variable
with the GET DIAGNOSTICS statement to perform exception checking.
This method conforms to X/Open and ANSI SQL standards and supports
multiple exceptions.
The next three sections describe how to use the SQLCODE variable
and the sqlca structure to perform exception handling. These
sections cover the following topics:
- Understanding the sqlca structure
- Using the SQLCODE variable to obtain error codes
- Checking for the different types of exceptions with the sqlca structure