It may be useful to build dependencies on the class (the first two characters)
of the SQLSTATEs.
For maximum diagnostic information, return the text message along with the
SQLSTATE (if applicable, the text message will also include the IBM defined
SQLSTATE). It is also useful for the application to print out the name of the
function that returns the error.
The following code segment from
utilcli.c
shows how diagnostic information
such as SQLSTATEs can be retrieved and displayed
.
Example 7 50 Handling SQLSTATE in CLI
void HandleDiagnosticsPrint(SQLSMALLINT htype, /* handle type identifier */
SQLHANDLE hndl /* handle */ )
{
SQLCHAR message[SQL_MAX_MESSAGE_LENGTH + 1];
SQLCHAR sqlstate[SQL_SQLSTATE_SIZE + 1];
SQLINTEGER sqlcode;
SQLSMALLINT length, i;
i = 1;
/* get multiple field settings of diagnostic record */
while (SQLGetDiagRec(htype,
hndl,
i,
sqlstate,
&sqlcode,
message,
SQL_MAX_MESSAGE_LENGTH + 1,
&length) == SQL_SUCCESS)
{
printf("\n SQLSTATE = %s\n", sqlstate);
printf(" Native Error Code = %ld\n", sqlcode);
printf("%s\n", message);
i++;
}
printf(" \n");
}
Note:
The code snippets provided in this chapter are for illustration purposes
only.
Utilcli.c
is sample code shipped with DB2 and can be found in the
SQLLIB/samples
directory.
Chapter 7. Application porting
215
footer
Our partners:
PHP: Hypertext Preprocessor Cheap Web Hosting
JSP Web Hosting
Ontario Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Java Hosting
Cheapest Hosting
Visionwebhosting.net Business web hosting division of Vision Web Hosting Inc.. All rights reserved