INFORMIX
DataBlade API Programmer's Manual
Chapter 12: DataBlade API Function Descriptions
Home Contents Index Master Index New Book

mi_db_error_raise()

The mi_db_error_raise() function raises an error or warning.

Syntax

The following formats are supported.

Format Meaning

d

integer

f,g,G,e,E

double (by reference)

T

text (lvarchar type, that is, a pointer to mi_lvarchar)

t

length followed by string (two separate parameters)

s

null-terminated C string

The second member of the pair is the value of the parameter.

Important: Terminate the parameter list arguments with a NULL pointer. If a NULL pointer does not terminate the list, the results are unpredictable.

Usage

The mi_db_error_raise() function can be invoked from either a client function or a server function. If it is invoked from a client function, the exception is passed to the database server for processing.

When mi_db_error_raise() is called, it signals an MI_Exception event. If the application has assigned a specific callback function to handle MI_Exception events, this callback is called. If no callback has been registered for MI_Exception conditions, DataBlade API uses the client default handler to handle the message.

You can use the mi_db_error_raise() function either to pass a literal message or to raise an SQL error or warning stored in the syserrors system catalog table. The syserrors table stores the text of error and warning messages along with their five-character SQLSTATE value.

If mi_db_error_raise() is used to return a literal message string, msg_type is MI_MESSAGE (a warning) or MI_EXCEPTION (an error), and msg contains the text of the message.

For example, both of the following lines return a message to the user:

For the first line, the database server sets the SQLSTATE value to 01U01 and the message text to Operation Successful. For the second line, the database server sets the SQLSTATE value to U0001 and the message text to Out of Memory!!! For more information about how Universal Server handles message text, see the Informix Guide to SQL: Syntax.

Important: In a server function, the MI_EXCEPTION flag directs the database server to abort current function processing and halt processing on the current SQL expression.The following example illustrates how the MI_EXCEPTION directive aborts a server function:

If mi_db_error_raise() is used to return a predefined SQLSTATE value, defined in the syserrors system catalog table, the following actions occur:

The query select * from syserrors; retrieves the current list of available SQL message strings. The locale column is used for the internationalization of error and warning messages.

For example, a function call follows to return a predefined SQL message that has no markers:

This returns the message Operation Interrupted.

To return a predefined SQL message that has one or more markers (text of the form %NAME%), you can specify values in parameter pairs to replace the markers with custom text.

For example, assume that the following message is under 2AM10 in the syserrors table:

The code to return the message follows:

This code returns the following message:

The code TOKEN%s indicates that the marker %TOKEN% should be replaced with the string "select" passed as the next argument. Parameter pairs do not have to be in the same order as the markers in the string.

Any supplied message text or message parameter strings are assumed to be in the database locale.

Parameter markers of the form %NAME% are assumed to be in single-byte ASCII characters only, to ensure that the markers will be independent of the locale used for the message.

Using the syserrors catalog table is recommended to maintain language independence.

Return Values

MI_OK

The function was successful.

MI_ERROR

The function was not successful. However, when this function is used in server functions to raise fatal errors that are not handled, the function does not return control to the calling function

Related Topics

For additional information, see the descriptions of the following functions: mi_errmsg(), mi_error_desc_copy(), mi_error_desc_destroy(), mi_error_desc_is_copy(), mi_error_level(), and mi_error_sql_state().




DataBlade API Programmer's Manual, version 9.1
Copyright © 1998, Informix Software, Inc. All rights reserved.