The following code fragment illustrates sending an RPC command with Client-Library. The fragment invokes an Adaptive Server Enterprise stored procedure rpctest:
create procedure rpctest
(@param1 int out,
@param2 int out,
@param3 int out,
@param4 int)
as
begin
select "rpctest is running."
select @param1 = 11
select @param2 = 22
select @param3 = 33
select @param1
return 123
end
The following code invokes rpctest from a Client-Library client. This fragment is from the ex08ct.c migration sample program.
CS_CONNECTION *conn;
CS_COMMAND *cmd;
... connection has been opened ...
/*
** Allocate a command structure.
*/
ret = ct_cmd_alloc(conn, &cmd);
EXIT_ON_FAIL(context, ret, "Could not allocate command structure."); /*
-- * Make the rpc. *
-- if (dbrpcinit(dbproc, "rpctest", (DBSMALLINT)0) == FAIL)
-- {
-- printf("dbrpcinit failed.\n");
-- dbexit();
-- exit(ERREXIT);
-- }
*/ /*
** Initiate an RPC command. In Client-Library ct_command is used for
** language commands (dbsqlexec or dbsqlsend commands in DB-Library),
** RPC commands (dbrpcinit), and text/image "send-data" commands
** (dbwritetext).
*/
ret = ct_command(cmd, CS_RPC_CMD, "rpctest", CS_NULLTERM, CS_UNUSED);
EXIT_ON_FAIL(context, ret, "Could not initiate RPC command."); /*
** Pass a value for each RPC parameter with ct_param. In this case,
** the required RPC parameters are the parameters in the definition of
** the rpctest stored procedure.
**
** The parameter’s name, datatype, and status (input-only or output)
** are passed within a CS_DATAFMT structure.
*/ /*
-- if (dbrpcparam
-- (dbproc, "@param1", (BYTE)DBRPCRETURN,
-- SYBINT4, -1, -1, ¶m1)
-- == FAIL)
-- {
-- printf("dbrpcparam failed.\n");
-- dbexit();
-- exit(ERREXIT);
-- }
*/ /*
** @param1 is integer (CS_INT) and is a return parameter.
** The datafmt.status field must be set to indicate whether
** each parameter is ’for output’ (CS_RETURN) or not
** (CS_INPUTVALUE)
*/ datafmt.datatype = CS_INT_TYPE;
datafmt.maxlength = CS_UNUSED;
datafmt.status = CS_RETURN;
strcpy(datafmt.name, "@param1");
datafmt.namelen = strlen(datafmt.name); ret = ct_param(cmd, &datafmt,
(CS_VOID *) (paramvals+1),
CS_UNUSED, 0);
EXIT_ON_FAIL(context, ret, "ct_param() for @param1 failed."); /*
-- if (dbrpcparam(dbproc, "@param2", (BYTE)0, SYBINT4,
-- -1, -1, ¶m2)
-- == FAIL)
-- {
-- printf("dbrpcparam failed.\n");
-- dbexit();
-- exit(ERREXIT);
-- }
*/ /*
** @param2 is integer (CS_INT) and is not a return parameter.
*/
datafmt.datatype = CS_INT_TYPE;
datafmt.maxlength = CS_UNUSED;
datafmt.status = CS_INPUTVALUE;
strcpy(datafmt.name, "@param2");
datafmt.namelen = strlen(datafmt.name); ret = ct_param(cmd, &datafmt,
(CS_VOID *) (paramvals+2),
CS_UNUSED, 0);
EXIT_ON_FAIL(context, ret, "ct_param() for @param2 failed."); /*
-- if (dbrpcparam
-- (dbproc, "@param3", (BYTE)DBRPCRETURN, SYBINT4,
-- -1, -1, ¶m3)
-- == FAIL)
-- {
-- printf("dbrpcparam failed.\n");
-- dbexit();
-- exit(ERREXIT);
-- }
*/ /*
** @param3 is integer (CS_INT) and is a return parameter.
*/
datafmt.datatype = CS_INT_TYPE;
datafmt.maxlength = CS_UNUSED;
datafmt.status = CS_RETURN;
strcpy(datafmt.name, "@param3");
datafmt.namelen = strlen(datafmt.name); ret = ct_param(cmd, &datafmt,
(CS_VOID *) (paramvals+3),
CS_UNUSED, 0);
EXIT_ON_FAIL(context, ret, "ct_param() for @param3 failed."); /*
-- if (dbrpcparam(dbproc, "@param4", (BYTE)0, SYBINT4,
-- -1, -1, ¶m4)
-- == FAIL)
-- {
-- printf("dbrpcparam failed.\n");
-- dbexit();
-- exit(ERREXIT);
-- }
*/ /*
** @param4 is integer (CS_INT) and is not a return parameter.
*/
datafmt.datatype = CS_INT_TYPE;
datafmt.maxlength = CS_UNUSED;
datafmt.status = CS_INPUTVALUE;
strcpy(datafmt.name, "@param4");
datafmt.namelen = strlen(datafmt.name); ret = ct_param(cmd, &datafmt,
(CS_VOID *) (paramvals+4),
CS_UNUSED, 0);
EXIT_ON_FAIL(context, ret, "ct_param() for @param4 failed."); /*
-- if (dbrpcsend(dbproc) == FAIL)
-- {
-- printf("dbrpcsend failed.\n");
-- dbexit();
-- exit(ERREXIT);
-- }
*/ /*
** Send the command to the server. The ct_send routine sends
** any kind of command, not just RPC commands.
*/
ret = ct_send(cmd);
EXIT_ON_FAIL(context, ret, "ct_send() failed.");
... deleted results processing code ...