Databases Reference
In-Depth Information
Example 4-11 Sample output of values stored in the SQLCA
sqlcaid: SQLCA ê
sqlcabc: 136
sqlcode: -1013
sqlerrml: 7
sqlerrmc: SAMPSLE
sqlerrd[0]: 0
sqlerrd[1]: 0
sqlerrd[2]: 0
sqlerrd[3]: 0
sqlerrd[4]: 0
sqlerrd[5]: 0
sqlwarn: 42705
sqlstate: 42705
Looking up the SQLCODE and SQLSTATE, we discover that the problem
resulted because the database manager could not find the database specified in
the application.
Alternatively, we can use a DB2 API called sqlaintp defined in sql.h to help get
more information about the error. This function will return the error text for an
SQLCODE in the SQLCA. An example of using this function is shown in
Example 4-12.
Example 4-12 Using the sqlaintp API to get error info
char errText[1000];
….
sqlaintp(errText,999,0,&sqlca);
printf("%s\n",errText);
The function call above retrieves the SQLCODE error message and stores it in a
buffer named errText . As input to the function, we provide the string buffer,
which stores the error message (errText), the size of the string buffer (999), the
maximum width of each line of the message text ('0' means no line breaks
needed in the text), and the pointer to the SQLCA structure (sqlca).
The function call will generate the following message:
SQL1013N The database alias name or database name "SAMPSLE" could not
be found. SQLSTATE=42705
After all this debugging, it appears the name of the database specified in our
code was incorrect. The line needs to be corrected to:
EXEC SQL CONNECT TO sample;
Search WWH ::




Custom Search