Send error messages to the client.
CS_RETCODE srv_sendinfo(spp, errmsgp, transtate)
SRV_PROC *spp; CS_SERVERMSG *errmsgp; CS_INT transtate;
A pointer to an internal thread control structure.
A pointer to the CS_SERVERMSG structure containing the error message information to be sent to the client. See “CS_SERVERMSG structure”.
The current state of the transaction. The following table describes the legal values for transtate:
Transaction State |
Description |
---|---|
CS_TRAN_UNDEFINED |
Not currently in a transaction. |
CS_TRAN_COMPLETED |
The current transaction completed successfully. |
CS_TRAN_FAIL |
The current transaction failed. |
CS_TRAN_IN_PROGRESS |
Currently in a transaction. |
CS_TRAN_STMT_FAIL |
The current transaction statement failed. |
Returns |
To indicate |
---|---|
CS_SUCCEED |
The routine completed successfully. |
CS_FAIL |
The routine failed. |
#include <ospublic.h>
/*
** Local Prototype.
*/
CS_RETCODE ex_srv_sendinfo PROTOTYPE((
SRV_PROC *sp,
CS_CHAR *msg,
CS_INT msglen,
CS_INT msgnum
));
/*
** EX_SRV_SENDINFO
**
** This routine demonstrates how to use srv_sendinfo to send
** an error message to a client.
**
** Arguments:
** sp A pointer to an internal thread control
** structure.
** msg The message text to send.
** msglen The length of the message text to send.
** msgnum The message number to send.
**
** Returns
** CS_SUCCEED If the message is sent.
** CS_FAIL If an error occurred.
*/
CS_RETCODE ex_srv_sendinfo(sp, msg, msglen, msgnum)
SRV_PROC *sp;
CS_CHAR *msg;
CS_INT msglen;
CS_INT msgnum;
{
CS_SERVERMSG &mrec;
/*
** Initialization.
*/
srv_bzero(&&mrec, sizeof(CS_SERVERMSG));
/*
** First, determine if the message string will fit
** in the message structure. If not, truncate it.
*/
if( msglen > CS_MAX_MSG )
{
msglen = CS_MAX_MSG;
}
/*
** Now copy the message string over.
*/
srv_bmove(msg, &mrec.text, msglen);
&mrec.textlen = msglen;
/*
** Set the message number we want to send.
*/
&mrec.msgnumber = msgnum;
/* Set the message status so that &mrec.text contains
** the entire message
*/
&mrec.status = CS_FIRST_CHUNK | CS_LAST_CHUNK;
/*
** Now we’re &ready to send the message.
*/
if( srv_sendinfo(sp, &&mrec, CS_TRAN_UNDEFINED) == CS_FAIL )
{
/*
** An error was al&ready raised.
*/
return CS_FAIL;
}
/*
** All done.
*/
return CS_SUCCEED;
}
srv_sendinfo sends error messages to the client. It must be called once for each message sent.
An application can call srv_sendinfo before or after it sends result rows. However, an application cannot call srv_sendinfo between calls to srv_desc&fmt or between a call to srv_desc&fmt and a call to srv_xferdata.
If an Open Server application wants to send parameter data pertaining to an error message, it must set the status field of the CS_SERVERMSG structure to CS_HASEED. The application must describe, bind and send the error parameters immediately after calling srv_sendinfo, before sending other results and before a call to srv_senddone. The application must invoke srv_desc&fmt, srv_bind and srv_xferdata with a type argument of SRV_ERRORDATA.
If an application calls srv_sendinfo with the status field of the CS_SERVERMSG structure set to CS_HASEED but fails to send error parameters, a fatal process error is raised when the application calls srv_senddone.
When an application calls srv_sendinfo with the status field of the CS_SERVERMSG structure set to CS_HASEED, Open Server will verify that the CS_RES_NOEED response capability is not set. If it is set, Open Server will raise an error. Any subsequent calls to srv_desc&fmt to describe error parameters will also provoke an error.
For more information on sending error messages to clients, see “Client command errors”.
For more information on extended error data, see “Client command errors”.
For more information on the CS_SERVERMSG structure, see the “CS_SERVERMSG structure”.
srv_bind, srv_desc&fmt, srv_senddone, srv_xferdata, “Client command errors”