Initialize a remote procedure call.
RETCODE dbrpcinit(dbproc, rpcname, options) DBPROCESS *dbproc; char *rpcname; DBSMALLINT options;
A pointer to the DBPROCESS structure that provides the connection for a particular front-end/server process. It contains all the information that DB-Library uses to manage communications and data between the front end and the server.
A pointer to the name of the stored procedure to be invoked.
A 2-byte bitmask of RPC options. So far, the only option available is DBRPCRECOMPILE, which causes the stored procedure to be recompiled before it is executed.
SUCCEED or FAIL.
An application can call a stored procedure in two ways: by executing a command buffer containing a Transact-SQL execute statement or by making a remote procedure call (RPC).
Remote procedure calls have a few advantages over execute statements:
An RPC passes the stored procedure’s parameters in their native datatypes, in contrast to the execute statement, which passes parameters as ASCII characters. Therefore, the RPC method is faster and usually more compact than the execute statement, because it does not require either the application program or the server to convert between native datatypes and their ASCII equivalents.
It is simpler and faster to accommodate stored procedure return parameters with an RPC, instead of an execute statement. With an RPC, the return parameters are automatically available to the application. (Note, however, that a return parameter must be specified as such when it is originally added to the RPC through the dbrpcparam routine.) If, on the other hand, a stored procedure is called with an execute statement, the return parameter values are available only if the command batch containing the execute statement uses local variables, not constants, as the return parameters. This involves additional parsing each time the command batch is executed.
To make a remote procedure call, first call dbrpcinit to specify the stored procedure that is to be invoked. Then call dbrpcparam once for each of the stored procedure’s parameters. Finally, call dbrpcsend to signify the end of the parameter list. This causes the server to begin executing the specified procedure. You can then call dbsqlok, dbresults, and dbnextrow to process the stored procedure’s results. (Note that you will need to call dbresults multiple times if the stored procedure contains more than one select statement.) After all of the stored procedure’s results have been processed, you can call the routines that process return parameters and status numbers, such as dbretdata and dbretstatus.
If the procedure being executed resides on a server other than the one to which the application is directly connected, commands executed within the procedure cannot be rolled back.
For an example of a remote procedure call, see the sample program example8.c.
dbnextrow, dbresults, dbretdata, dbretstatus, dbrpcparam, dbrpcsend, dbsqlok