Logo Search packages:      
Sourcecode: freetds version File versions

int tds_submit_execute ( TDSSOCKET *  tds,
TDSDYNAMIC *  dyn 
)

tds_submit_execute() sends a previously prepared dynamic statement to the server. Currently works with TDS 5.0 or TDS7+

Parameters:
dyn dynamic proc to execute. Must build from same tds.

Definition at line 503 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(), and tds_submit_execute().

Referenced by tds_submit_execute().

{
TDSCOLINFO *param;
TDSPARAMINFO *info;
int id_len;
int i;

      tdsdump_log(TDS_DBG_FUNC, "%L inside tds_submit_execute()\n");

      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;
      }

      /* TODO check this code, copied from tds_submit_prepare */
      tds_free_all_results(tds);
      tds->rows_affected = 0;
      tds->state = TDS_QUERYING;

      tds->cur_dyn = dyn;

      if (IS_TDS7_PLUS(tds)) {
            /* RPC on sp_execute */
            tds->out_flag = 3;      /* RPC */
            /* procedure name */
            tds_put_smallint(tds, 10);
            tds_put_n(tds, "s\0p\0_\0e\0x\0e\0c\0u\0t\0e", 20);
            tds_put_smallint(tds, 0);     /* flags */

            /* id of prepared statement */
            tds_put_byte(tds, 0);
            tds_put_byte(tds, 0);
            tds_put_byte(tds, SYBINT4);
            tds_put_int(tds, dyn->num_id);

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

            return tds_flush_packet(tds);
      }

      tds->out_flag = 0x0F;
      /* dynamic id */
      id_len = strlen(dyn->id);

      tds_put_byte(tds, TDS5_DYNAMIC_TOKEN);
      tds_put_smallint(tds, id_len + 5);
      tds_put_byte(tds, 0x02);
      tds_put_byte(tds, 0x01);
      tds_put_byte(tds, id_len);
      tds_put_n(tds, dyn->id, id_len);
      tds_put_smallint(tds, 0);

      tds_put_params(tds, dyn->params, 0);

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


Generated by  Doxygen 1.6.0   Back to index