Error information in the SQLCODE, SQLSTATE, and SQLWARN fields
A source file containing executable SQL statements can provide
at least one SQLCA structure with the name sqlca
.
The SQLCA structure is defined in the SQLCA include file. Source files
without embedded SQL statements, but calling database manager APIs,
can also provide one or more SQLCA structures, but their names are
arbitrary.
If your application is compliant with the FIPS 127-2 standard, you can declare the SQLSTATE and SQLCODE as host variables for C, C++, COBOL, and FORTRAN applications, instead of using the SQLCA structure.
An SQLCODE value of 0 means successful execution (with possible SQLWARN warning conditions). A positive value means that the statement was successfully executed but with a warning, as with truncation of a host variable. A negative value means that an error condition occurred.
An additional field, SQLSTATE, contains a standardized error code consistent across other IBM® database products and across SQL92-conformant database managers. Practically speaking, you should use SQLSTATE values when you are concerned about portability since SQLSTATE values are common across many database managers.
The first element of the SQLWARN array, SQLWARN0, contains a blank
if all other elements are blank. SQLWARN0 contains a W
if at least one other element contains a warning character.
- Where possible, have your applications check the SQLSTATE rather than the SQLCODE.
- If your applications will use Db2 Connect, consider using the mapping facility provided by Db2 Connect to map SQLCODE conversions between unlike databases.