Logo Search packages:      
Sourcecode: freetds version File versions

int tds_submit_rpc ( TDSSOCKET *  tds,
const char *  rpc_name,
TDSPARAMINFO params 
)

tds_submit_rpc() call a RPC from server. Output parameters will be stored in tds->param_info

Parameters:
rpc_name name of RPC
params parameters informations. NULL for no parameters

Definition at line 696 of file query.c.

References tds_result_info::columns, tds_result_info::current_row, tds_result_info::num_cols, tds_client_msg(), tds_flush_packet(), tds_put_string(), and tds_submit_rpc().

Referenced by tds_submit_rpc().

{
      TDSCOLINFO *param;
      int rpc_name_len, i;
      int num_params = params ? params->num_cols : 0;

      assert(tds);
      assert(rpc_name);

      if (tds->state == TDS_PENDING) {
            tds_client_msg(tds->tds_ctx, tds, 20019, 7, 0, 1,
                         "Attempt to initiate a new SQL Server operation with results pending.");
            return TDS_FAIL;
      }

      tds_free_all_results(tds);
      tds->rows_affected = 0;
      tds->state = TDS_QUERYING;

      /* distinguish from dynamic query  */
      tds->cur_dyn = NULL;

      rpc_name_len = strlen(rpc_name);
      if (IS_TDS7_PLUS(tds)) {
            tds->out_flag = 3;      /* RPC */
            /* procedure name */
            tds_put_smallint(tds, rpc_name_len);
            tds_put_string(tds, rpc_name, rpc_name_len);
            /* TODO support flags
             * bit 0 (1 as flag) in TDS7/TDS5 is "recompile"
             * bit 1 (2 as flag) in TDS7+ is "no metadata" bit 
             * (I don't know meaning of "no metadata") */
            tds_put_smallint(tds, 0);

            for (i = 0; i < num_params; i++) {
                  param = params->columns[i];
                  tds_put_data_info(tds, param, TDS_PUT_DATA_USE_NAME);
                  tds_put_data(tds, param, params->current_row, i);
            }

            return tds_flush_packet(tds);
      }

      if (IS_TDS50(tds)) {
            tds->out_flag = 0xf;    /* normal */

            /* DBRPC */
            tds_put_byte(tds, TDS_DBRPC_TOKEN);
            tds_put_smallint(tds, rpc_name_len + 3);
            tds_put_byte(tds, rpc_name_len);
            tds_put_string(tds, rpc_name, rpc_name_len);
            /* TODO flags */
            tds_put_smallint(tds, num_params ? 2 : 0);

            if (num_params)
                  tds_put_params(tds, params, TDS_PUT_DATA_USE_NAME);

            /* send it */
            return tds_flush_packet(tds);
      }

      /* TODO continue, support for TDS4?? */
      return TDS_FAIL;
}


Generated by  Doxygen 1.6.0   Back to index