SQL/MP Programming Manual for C
Error and Status Reporting
HP NonStop SQL/MP Programming Manual for C—429847-008
9-4
Returning Error and Warning Information
The C external declaration generated by the INCLUDE SQLCA EXTERNAL directive
is:
extern struct SQLCA_TYPE sqlca;
The C external declaration generated by the INCLUDE SQLSA EXTERNAL directive
is:
extern struct SQLSA_TYPE sqlsa;
Returning Error and Warning Information
NonStop SQL/MP provides these methods that you can use to process errors and
warnings in a program:
Checking the sqlcode variable
Using the WHENEVER directive
Checking information from the SQLCA structure
Checking the sqlcode Variable
NonStop SQL/MP returns an error or warning code to sqlcode after the execution of
each embedded SQL statement or directive as follows:
Each SQL/MP error or warning message has an assigned code. For these codes and
their meanings, see the SQL/MP Messages Manual.
Declaring the sqlcode Variable
Declare sqlcode as a type short variable within the scope of each embedded SQL
statement. One method is to declare sqlcode as a global variable at the start of each
C source module that contains embedded SQL statements.
#pragma SQL
/* Other pragmas, directives, and comments */
...
short sqlcode;
...
Use C conditional statements to check the sqlcode variable. Example 9-1 on
page 9-5 inserts two column values into the PARTS table and then checks sqlcode
for any errors and warnings.
Value Status
< 0
Error
> 0
Warning
0
Successful