A CS_SERVERMSG structure contains information about a server error message.
Open Server uses a CS_SERVERMSG structure to send error messages to a client, through the srv_sendinfo routine.
A CS_SERVERMSG structure is defined as follows:
/*
** CS_SERVERMSG
** The server message structure.
*/
typedef struct _cs_servermsg
{
CS_INT msgnumber;
CS_INT state;
CS_INT severity;
CS_CHAR text[CS_MAX_MSG];
CS_INT textlen;
CS_CHAR svrname[CS_MAX_NAME];
CS_INT svrnlen;
/*
** If the error involved a stored procedure,
** the following fields contain information
** about the procedure:
*/
CS_CHAR proc[CS_MAX_NAME];
CS_INT proclen;
CS_INT line;
/*
** Other information.
*/
CS_INT status;
CS_BYTE sqlstate[CS_SQLSTATE_SIZE];
CS_INT sqlstatelen;
} CS_SERVERMSG;
where:
msgnumber is the Open Server or application message number to report to the client.
state is the state in which the message was generated. The application defines this.
severity is the severity of the message.
text is the text of the message.
textlen is the length, in bytes, of text.
svrname is the name of the server that generated the message. This value can be the name of the Open Server application running currently, or a different name.
svrnlen is the length, in bytes, of svrname.
proc is the name of the stored procedure (if any) that caused the message.
proclen is the length, in bytes, of proc.
line is the line number within the stored procedure (if any) that caused the message.
status contains information on whether the message chunk is the first, last, or a middle part of the message, and whether it includes extended error data. Since status is a byte-ordered flag, you can set it to more than one value. For example:
mrec.status = CS_FIRST_CHUNK | CS_LAST_CHUNK;
where mrec is declared as a CS_SERVERMSG structure.
Table 2-10 describes the legal values for status:
Value |
Meaning |
---|---|
CS_HASEED |
There is extended error data associated with the message. |
CS_FIRST_CHUNK |
The message text contained in text is the first chunk of the message. If CS_FIRST_CHUNK and CS_LAST_CHUNK are both on, then text contains the entire message. If neither CS_FIRST_CHUNK nor CS_LAST_CHUNK is on, then text contains a middle chunk of the message. |
CS_LAST_CHUNK |
The message text contained in text is the last chunk of the message. If CS_FIRST_CHUNK and CS_LAST_CHUNK are both on, then text contains the entire message. If neither CS_FIRST_CHUNK nor CS_LAST_CHUNK is on, then text contains a middle chunk of the message. |
sqlstate is a byte string describing the error.
Not all server messages have SQL state values associated with them. If no SQL state value is associated with a message, sqlstate’s value is “ZZZZZ”.
sqlstatelen is the length, in bytes, of the sqlstate string.