Home | Previous Page | Next Page   Database Access > Handling Exceptions and Events > Database Server Exceptions >

Understanding Database Server Exceptions

A database server exception is an unexpected condition that occurs within the database server. A database server exception can occur in any of the following tasks:

When the database server encounters a database server exception, it raises the MI_Exception event.

Warnings and Errors

The MI_Exception event indicates which of the following status conditions has caused the database server exception:

The following list describes the most common DataBlade API library errors:

Potential exceptions other than these types of common invalid arguments are mentioned in the Return Values section of the individual function descriptions in the IBM Informix: DataBlade API Function Reference.

An error descriptor for an MI_Exception event indicates the status condition of the event with one of the following exception levels.

Status Condition Exception Level Description
Warning MI_MESSAGE Raised when the database server generates a warning or an informational message. The database server passes a warning back to the client application; it is up to the client to display the warning message.
Runtime error
(failure)
MI_EXCEPTION Raised when the database server generates a runtime error.

The mi_error_level( ) function returns the exception level from an error descriptor for the MI_Exception event.

Status Variables

To identify the particular cause of an exception, the database server sets the following status variables:

SQLSTATE Status Value

SQLSTATE is a five-character string that the database server sets after it executes each DataBlade API function. The value of SQLSTATE indicates the status of the function execution.

American National Standards Institute

The SQLSTATE status variable is compliant with ANSI and X/Open standards.

End of American National Standards Institute

This five-character code consists of a two-character class code and a three-character subclass code. In Figure 58, "IX" is the class code and "000" is the subclass code. The SQLSTATE value "IX000" indicates that an Informix-specific error has occurred.

Figure 58. The Structure of the SQLSTATE Code with the Value "IX000"
begin figure description - This figure is described in the surrounding text. - end figure description

SQLSTATE can contain only digits and capital letters. The class code is unique but the subclass code is not. The meaning of the subclass code depends on the associated class code. The initial character of the class code indicates the source of the exception, as Table 69 summarizes.

Table 69. Initial SQLSTATE Class-Code Values
Initial Class-Code Value Source of Exception Code Notes
0 to 4
A to H
X/Open and ANSI/ISO The associated subclass codes also begin in the range 0 to 4 or A to H.
5 to 9 Defined by the implementation Subclass codes are also defined by the implementation.
I to Z Dynamic Server,
a DataBlade module,
a C UDR,
a client LIBMI application
Any of the Informix-specific error messages (those that the X/Open or ANSI/ISO reserved range does not support) have an initial class-code value of "I" (SQLSTATE value of "IX000").

If a UDR returns an error message that this routine has defined, the initial class-code value is "U" (SQLSTATE value of "U0001").

Other SQLSTATE class-code values can be defined by the implementation.

After the database server executes a DataBlade API function, it sets SQLSTATE to indicate one of the status conditions, as Table 70 shows.

Table 70. Status Conditions in SQLSTATE
Status
Condition
SQLSTATE Value
Class Code Subclass Code
Success "00" "000"
Success, but no rows found "02" "000"
Success, but warnings generated "01" For ANSI and X/Open warnings:
"000" to "006"

For Informix-specific warnings:

"I01" to "I11"

For literal warnings that DataBlade API modules raise:

"U01"

For custom warnings that DataBlade API modules define: other subclass values, as defined in the syserrors system catalog table

Failure, runtime error generated For ANSI and X/Open errors: > "02"

For Informix-specific errors: "IX"

For literal errors that DataBlade API modules raise: "U0"

For custom errors that DataBlade API modules define: other class codes, as defined in the syserrors system catalog table

Error-specific value

For a list of reserved ANSI and X/Open values for SQLSTATE, see the description of the GET DIAGNOSTICS statement in the IBM Informix: Guide to SQL Syntax. For more information on DataBlade API literal exceptions ("U0001" and "01U01"), see Passing Literal Messages. For more information on DataBlade API custom exceptions, see Raising Custom Messages.

Identifying Warnings with SQLSTATE

When the database server executes a DataBlade API function successfully but encounters a warning condition, it takes the following actions:

Identifying Runtime Errors with SQLSTATE

When an SQL statement results in a runtime error, the database server takes the following actions:

The actual class and subclass codes of SQLSTATE identify the particular error. For Informix-specific errors (SQLSTATE is "IX000"), you can also check the value of the SQLCODE variable to identify the error.

Tip:
The database server sets SQLSTATE to "02000" (class = "02") when a SELECT or FETCH statement encounters NOT FOUND (or END OF DATA). However, the NOT FOUND condition does not cause a database server exception. Therefore, you do not use SQLSTATE to detect this condition from within a callback of a DataBlade API module. Instead, your DataBlade API module can check for the MI_NO_MORE_RESULTS return code from the mi_get_result( ) function. For more information, see Retrieving Query Data.
SQLCODE Status Value

Each SQLSTATE value also has an associated Informix-specific status code. The database server saves this Informix-specific status code in the SQLCODE status variable. The SQLCODE variable is an integer that indicates whether the SQL statement succeeded or failed.

When the database server executes an SQL statement, the database server automatically updates the SQLCODE variable. After an SQL statement executes, the SQLCODE variable can indicate one of the status conditions that Table 71 shows.

Table 71. Status Conditions In SQLCODE
Status Condition SQLCODE Value
Success 0
Success, but no rows found 100
Success, but warnings generated not available directly from SQLCODE
Failure, runtime error generated < 0
Identifying Warnings with SQLCODE

When the database server executes an SQL statement successfully but encounters a warning condition, it takes the following actions:

To identify warnings, examine the value of SQLSTATE. The SQLCODE value does not indicate the cause of a warning. For more information, see Identifying Warnings with SQLSTATE.

Identifying Runtime Errors with SQLCODE

When an SQL statement results in a runtime error, the database server takes the following actions:

The actual number in SQLCODE identifies the particular Informix runtime error. The finderr or Error Messages utility lists error messages and describes corrective actions.

Tip:
The database server sets SQLCODE to 100 when a SELECT or FETCH statement encounters NOT FOUND (or END OF DATA). However, the NOT FOUND condition does not cause a database server exception. Therefore, you do not use SQLCODE to detect this condition from within a callback of a DataBlade API module. Instead, your DataBlade API module can check for the MI_NO_MORE_RESULTS return code from the mi_get_result( ) function. For more information, see Retrieving Query Data.
Home | [ Top of Page | Previous Page | Next Page | Contents | Index ]