Setting a SQLCODE Value on Error
Go Up to Handling Error Conditions
For DSQL applications, error conditions should be cast in terms of SQL conventions. SQL applications typically report errors through a variable, SQLCODE
, declared by an application. To translate an InterBase error code into SQLCODE
format, use isc_sqlcode()
. This function searches the error status vector for an InterBase error code that can be translated into a SQL error code, and performs the translation. Once SQLCODE
is set, the other API functions for handling SQL errors, isc_print_sqlerror()
, and isc_sql_interprete()
, can be called.
isc_sqlcode()
requires one parameter, a pointer to the status vector. It returns a long value, containing a SQL error code. The following code illustrates the use of this function:
#include <ibase.h>;
. . .
long SQLCODE; /* Declare the SQL error code variable. */
ISC_STATUS status_vector[20];
. . .
if (status_vector[0] == 1 && status_vector[1] > 0) {
SQLCODE = isc_sqlcode(status_vector);
isc_print_sqlerror(SQLCODE, status_vector)
. . .
}
If successful, isc_sqlcode()
returns the first valid SQL error code decoded from the status vector. If no valid SQL error code is found, isc_sqlcode()
returns –999.