Read or respond to a client dynamic SQL command.
CS_RETCODE srv_dynamic(spp, cmd, item, bufp,
buflen, outlenp)
SRV_PROC *spp; CS_INT cmd; CS_INT item; CS_VOID *bufp CS_INT buflen; CS_INT *outlenp
A pointer to an internal thread control structure.
Indicates whether a dynamic command is being read from or sent to a client. Table 3-38 describes the legal values for cmd:
Value |
Description |
---|---|
CS_SET |
srv_dynamic is sending a response to a dynamic command back to a client. |
CS_GET |
srv_dynamic is reading a dynamic command from a client. |
Indicates what kind of information is being sent or retrieved. Table 3-39 describes the legal values for item:
Value |
Meaning |
---|---|
SRV_DYN_TYPE |
The type of dynamic operation being performed. |
SRV_DYN_IDLEN |
The length of the dynamic statement ID. |
SRV_DYN_ID |
The dynamic statement ID. |
SRV_DYN_STMTLEN |
The length of the dynamic statement. |
SRV_DYN_STMT |
The dynamic statement that is being prepared or executed. |
A pointer to the buffer in which the item value is returned (CS_GET) or set (CS_SET).
The length, in bytes, of the *bufp buffer. Table 3-40 summarizes the required buffer sizes:
Value |
Required format (size) |
---|---|
SRV_DYN_TYPE |
sizeof(CS_INT). |
SRV_DYN_IDLEN |
sizeof(CS_INT). |
SRV_DYN_ID |
Varies. Determine length by first calling srv_dynamic with item set to CS_DYN_IDLEN and then allocate buffer size accordingly. |
SRV_DYN_STMTLEN |
sizeof(CS_INT). |
SRV_DYN_STMT |
Varies. Determine length by first calling srv_dynamic with item set to CS_DYN_STMTLEN and then allocate buffer size accordingly. |
A pointer to an integer variable which is set to the actual length of data copied into *bufp when retrieving data from the client (cmd is CS_GET). This argument is not required if cmd is CS_SET.
Returns |
To indicate |
---|---|
CS_SUCCEED |
The routine completed successfully. |
CS_FAIL |
The routine failed. |
#include <ospublic.h>
/*
** Local Prototype
*/
extern CS_RETCODE ex_srv_dynamic PROTOTYPE((
CS_VOID *spp,
CS_INT *optypep
));
/*
** EX_SRV_DYNAMIC
**
** Example routine to retrieve dynamic operation type from a
** client.
**
** Arguments:
** spp Thread control structure.
** optypep Dynamic operation type.
**
** Returns:
**
** CS_SUCCEED Dynamic information was retrieved
** successfully.
** CS_FAIL An error was detected.
*/
CS_RETCODE ex_srv_dynamic(spp, optypep)
SRV_PROC *spp;
CS_INT *optypep;
{
CS_INT outlen;
if(srv_dynamic(spp, CS_GET, SRV_DYN_TYPE, optypep,
sizeof(*optypep), &outlen) == CS_FAIL)
{
return(CS_FAIL);
}
return(CS_SUCCEED);
}
The srv_dynamic routine allows an Open Server application to read a dynamic SQL command or send a response to such a command.
Valid operation types (SRV_DYN_TYPE) include:
CS_PREPARE – prepare a statement (CS_GET only).
CS_DESCRIBE_INPUT – request input parameter formats for the current prepared statement (CS_GET only).
CS_DESCRIBE_OUTPUT – request column formats for the current prepared statement (CS_GET only).
CS_EXECUTE – execute a prepared statement (CS_GET only).
CS_EXEC_IMMEDIATE – execute an unprepared statement, which has no parameters and does not return results (CS_GET only).
CS_DEALLOC – deallocate a prepared statement (CS_GET only).
CS_ACK – acknowledge a dynamic SQL command from client (CS_SET only).
Each dynamic command received from a client triggers a SRV_DYNAMIC event. An Open Server application can then call srv_dynamic, in response to each client dynamic command, to retrieve and store the operation type, statement ID and statement, and then acknowledge the client communication, by issuing a srv_dynamic call with type set to CS_ACK.
It is an error to call srv_dynamic in any event handler other than a SRV_DYNAMIC handler.
CS_ACK is the only dynamic operation type that can be set (cmd set to CS_SET).
CS_PREPARE, CS_DESCRIBE_INPUT, CS_DESCRIBE_OUTPUT, CS_EXECUTE, CS_EXEC_IMMEDIATE and CS_DEALLOC are the only dynamic operation types that can be retrieved (cmd set to CS_GET).
Sending a full dynamic SQL response to a client requires passing the ID length, the ID, and the operation type. This requires three distinct calls to srv_dynamic. It is an error, for example, to set just the statement ID and then call srv_senddone. The only exception is if the operation type is CS_EXEC_IMMEDIATE, for which there is no associated statement ID.
Parameter data formats and output column formats can be sent to a client, in response to a CS_PREPARE dynamic command, using srv_descfmt and srv_xferdata with a type argument of SRV_DYNDATA. Note that srv_bind is not necessary here, as the application is simply sending formats.
An Open Server application retrieves and store the parameter data sent by a client following the CS_EXECUTE dynamic command using srv_descfmt, srv_bind, and srv_xferdata, with a type argument of SRV_DYNDATA. The application determines the number of parameters using srv_numparams.
The application sends dynamic SQL result rows to the client, in response to a CS_EXECUTE dynamic SQL command, using srv_descfmt, srv_bind, and srv_xferdata with a type argument of SRV_ROWDATA.
A dynamic SQL command of CS_EXEC_IMMEDIATE indicates that the client wishes to execute a statement without parameters and receive only a DONE as a result. The statement is contained in the CS_EXEC_IMMEDIATE command stream and is accessible through SRV_DYN_STMT. The statement has not been previously prepared—the statement ID length (SRV_DYN_IDLEN) will be 0—and will cease to exist once the SRV_DYNAMIC event handler has exited.
srv_bind, srv_descfmt, srv_numparams, srv_xferdata, “Dynamic SQL”