Capturing SQL Error Messages

From InterBase

Go Up to Setting a SQLCODE Value on Error


Use isc_sql_interprete() to build a SQL error message based on a specific SQL error code and store it in a buffer defined by an application. Capturing messages in a buffer is useful when applications:

  • Run under windowing systems that do not permit direct screen writes.
  • Store a record of all error messages in a log file.
  • Manipulate or format error messages for display or pass them to a windowing system’s display routines.

isc_sql_interprete() requires three parameters: a valid SQL error code, usually passed as a variable named SQLCODE, a buffer where the SQL message should be stored, and the size of the buffer. The following code illustrates how this function might be called to build a message string and store it in a log file:

#include <ibase.h>
. . .
ISC_STATUS status_vector[20];
isc_tr_handle trans;
long SQLCODE;
char msg[512];
FILE *efile; /* Code fragment assumes pointer to an open file. */
trans = 0L;
. . .
/* Assume a transaction, trans, is started here. */
/* Assume an API call returning status information is called here. */
. . .
/* Error-handling routine starts here. */
if (status_vector[0] == 1 && status_vector[1] > 0) {
SQLCODE = isc_sqlcode(status_vector);
isc_sql_interprete(SQLCODE, msg, 512);
fprintf(efile, "%s\n", msg);
isc_rollback_transaction(status_vector, &trans);
return(1);
}
Note:
This code fragment assumes that the log file is properly declared and opened elsewhere in the application before control is passed to this error handler.

Advance To: