MESSAGE Statement

Displays a message.

Syntax

MESSAGE expression, …
[ TYPEINFO | ACTION | WARNING | STATUS } ]
[ TOCONSOLE
 | CLIENTFOR { CONNECTION conn_id  [ IMMEDIATE ] | ALL } ]
 | [ EVENT | SYSTEM ] LOG } 
 [ DEBUG ONLY ] ]

Parameters

Examples

Usage

The MESSAGE statement displays a message, which can be any expression. Clauses can specify where the message is displayed.

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.

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 a SQL statement. If the recipient is currently executing a 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.

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.

For more information about using callback functions, see SQL Anywhere Server - Programming > Database tools interface (DBTools) > Using the database tools interface > Using callback functions.
Note: This reference points to SQL Anywhere documentation.

TYPE—The TYPE clause has an effect only if the message is sent to the client. The client application must decide how to handle the message. Interactive SQL displays messages in these locations:

  • INFO – The Message window (default).

  • ACTION– A Message box with an OK button.

  • WARNING – A Message box with an OK button.

  • STATUS – The Messages pane.

TO—Specifies the destination of a message:

  • CONSOLE – Send messages to the database server window. CONSOLE is the default.

  • CLIENT – Send messages to the client application. Your application must decide how to handle the message, and you can use the TYPE as information on which to base that decision.

  • LOG – Send messages to the server log file specified by the -o option.

FOR—For messages TO CLIENT, this clause specifies which connections receive notification about the message:

DEBUG ONLY—Lets you control whether debugging messages added to stored procedures are enabled or disabled by changing the setting of the DEBUG_MESSAGES option. When DEBUG ONLY is specified, the MESSAGE statement is executed only when the DEBUG_MESSAGES option is set to ON.
Note: DEBUG ONLY messages are inexpensive when the DEBUG_MESSAGES option is set to OFF, so these statements can usually be left in stored procedures on a production system. However, they should be used sparingly in locations where they would be executed frequently; otherwise, they might result in a small performance penalty.

Standards

  • SQL—Vendor extension to ISO/ANSI SQL grammar.

  • Sybase—Not supported in Adaptive Server Enterprise. The Transact-SQL PRINT statement provides a similar feature, and is available in SQL Anywhere.

Permissions

Must be connected to the database.

DBA authority is required to execute a MESSAGE statement containing a FOR clause.

Related reference
CREATE PROCEDURE Statement
WAITFOR Statement
DEBUG_MESSAGES Option