Handling a Remote Stored Procedure Event

This example shows how the rpc_execute callback function in GATECBS.C sends a remote stored procedure to, and receives results from, a remote database.

  1. Define the rpc_execute function and the following parameters:
    DBPROCESS *rmtproc;     // DBPROCESS pointer  
    int i;                  // Index variable     
    short params;
    short retparam;
    short *paramarray;
    DBCHAR complete_rpc_name[4 * (MAXNAME  1)];//Database.owner.name;#
    
  2. Get the remote DBPROCESS pointer *rmtproc in the SRV_PROC connection structure with srv_getuserdata. This is a pointer that was saved using srv_setuserdata after the client connected to a remote database.
    rmtproc = ((REMOTE_DBMS *)srv_getuserdata(srvproc))->dbproc;
    paramarray = ((REMOTE_DBMS *)srv_getuserdata(srvproc))->retparams;
    
  3. Get the remote stored procedure name and initialize the remote stored procedure to the remote database management system:
    dbrpcinit(rmtproc, complete_rpc_name,
        (DBUSMALLINT)srv_rpcoptions(srvproc));
    
    // Set up any RSP parameters.  
    
    params = srv_rpcparams(srvproc);
    retparam = 1;
    for (i = 1; i <= params; i+)
    {
        rpc_paramname = srv_paramname(srvproc, i, (int *)NULL);
        if (!strlen(rpc_paramname))
            rpc_paramname = NULL;
        rpc_paramstatus = (BYTE)srv_paramstatus(srvproc, i);
        rpc_paramtype = srv_paramtype(srvproc, i);
        rpc_parammaxlen = srv_parammaxlen(srvproc, i);
        rpc_paramlen = srv_paramlen(srvproc, i);
        rpc_paramdata = srv_paramdata(srvproc, i);
        dbrpcparam(rmtproc,rpc_paramname,rpc_paramstatus,rpc_paramtype,
            rpc_parammaxlen,rpc_paramlen, rpc_paramdata);
    
    // Not all parameters are return parameters. Map each return     
    // parameter to its original parameter to later reset the return 
    // value of the correct return parameters in "handle_results()". 
    
    if((BYTE)srv_paramstatus(srvproc, i) & SRV_PARAMRETURN) {
          paramarray[retparam] = i;
          retparam+;
    }
    
  4. Send the remote stored procedure to the remote database using the DB-Library dbrpcsend function:
    dbrpcsend(rmtproc);
    dbsqlok(rmtproc);
    
  5. Get the remote database results and pass them back to the client using the handle_results function:
    handle_results(rmtproc, srvproc);
    return (SRV_CONTINUE);