Retrieves error, warning, and informational messages from Client-Library.
get diagnostics {:hv = statement_info [, :hv = statement_info]…| exception :condition_number :hv = condition_info [, :hv = condition_info]…}
The keyword number is currently the only supported statement_info type. It returns the total number of exceptions in the diagnostics queue.
Any one of the keywords sqlca_info, sqlcode_number, and returned_sqlstate.
exec sql begin declare section;
CS_INT num_msgs;
CS_INT condcnt=1;
exec sql include sqlca;
exec sql end declare section;
exec sql exec sp_password "bass", "foo";
exec sql get diagnostics :num_msgs = number;
printf("Number of messages is %d.\n", num_msgs);
/* Loop through and print the messages. */
while (condcnt <= num_msgs)
{ exec sql get diagnostics exception :condcnt :sqlca = sqlca_info; printf("SQLCODE = %d \n", sqlca.sqlcode);
printf("%s \n", sqlca.sqlerrm.sqlerrmc);
condcnt = condcnt + 1;
}
Many Embedded SQL statements are capable of causing multiple warnings or errors. Typically, only the first error is reported using SQLCODE, SQLCA, or SQLSTATE. Use get diagnostics to process all the errors.
You can use get diagnostics, which is the target of the call, perform, or go to clause of a whenever statement, in the code.
You can use get diagnostics after a statement for which you want to retrieve informational messages.
whenever