Displays a message, which can be any expression. Clauses can specify where the message is displayed.
MESSAGE expression, … [ TYPE { INFO | ACTION | WARNING | STATUS } ] [ TO { CONSOLE | CLIENT [ FOR { CONNECTION conn_id [ IMMEDIATE ] | ALL } ] | [ EVENT | SYSTEM ] LOG } [ DEBUG ONLY ] ]
Typically, messages sent using the IMMEDIATE clause are delivered in less than five seconds, even if the destination connection is not making database server requests. Message delivery could be delayed if the client connection makes several requests per second, receives very large BLOB data, or if the client's message callback executes for more than a second. In addition, sending more than one IMMEDIATE message to a single connection every two seconds could delay message delivery or generate an error message. If the client connection is disconnected, a successful MESSAGE...IMMEDIATE statement may not be delivered.
The FOR clause can be used to notify another application of an event detected on the server without the need for the application to explicitly check for the event. When the FOR clause is used, recipients receive the message the next time they execute an SQL statement. If the recipient is currently executing an SQL statement, the message is received when the statement completes. If the statement being executed is a stored procedure call, the message is received before the call is completed.
If an application requires notification within a short time after the message is sent and when the connection is not executing SQL statements, you can use a second connection. This connection can execute one or more WAITFOR DELAY statements. These statements do not consume significant resources on the server or network (as would happen with a polling approach), but permit applications to receive notification of the message shortly after it is sent.
CREATE PROCEDURE message_test () BEGIN MESSAGE 'The current date and time: ', Now(); END; CALL message_test();
void SQL_CALLBACK my_msgproc( void * sqlca, unsigned char msg_type, long code, unsigned short len, char* msg ) { … }
Install the declared message handler by calling the SQLSetConnectAttr function:
rc = SQLSetConnectAttr( dbc, ASA_REGISTER_MESSAGE_CALLBACK, (SQLPOINTER) &my_msgproc, SQL_IS_POINTER );
The procedure issuing a MESSAGE … TO CLIENT statement must be associated with a connection.
For example, the message box is not displayed because the event occurs outside of a connection:
CREATE EVENT CheckIdleTime TYPE ServerIdle WHERE event_condition( 'IdleTime' ) > 100 HANDLER BEGIN MESSAGE 'Idle engine' type warning to client; END;
However, in this example, the message is written to the server console:
CREATE EVENT CheckIdleTime TYPE ServerIdle WHERE event_condition( 'IdleTime' ) > 100 HANDLER BEGIN MESSAGE 'Idle engine' type warning to console; END;
Valid expressions can include a quoted string or other constant, variable, or function. However, queries are not permitted in the output of a MESSAGE statement, even though the definition of an expression includes queries.
ESQL and ODBC clients receive messages via message callback functions. In each case, these functions must be registered. To register ESQL message handlers, use the db_register_callback function.
ODBC clients can register callback functions using the SQLSetConnectAttr function.