ct_command

Description

Initiates a language request or remote procedure call (RPC).

Syntax

CS_RETCODE (command, type, buffer, buf_len, option);
CS_COMMAND    *command;
CS_INT        type;
CS_BYTE       *buffer;
CS_INT        buf_len;
CS_INT        option;

Parameters

command

(I) Handle for this client/server operation. This handle is defined in the associated ct_cmd_alloc call. The command handle corresponds to the TDPROC handle in the Open ServerConnect Gateway-Library.

type

(I) Type of request to initiate. The following symbolic values are legal for type:

When type Is

ct_command Initiates

Buffer contains

CS_LANG_CMD (148)

A language request.

The text of the language request.

CS_RPC_CMD (149)

A remote procedure call.

The name of the remote procedure.

buffer

(I) Variable (buffer) that contains the language request or RPC name.

This argument is typically one of the following datatypes:

	int buffer[n];
	char buffer[n];
buf_len

(I) Length, in bytes, of the buffer.

If the value in the buffer is a fixed-length or symbolic value, assign buf_len a value of CS_UNUSED.

option

Option associated with this request, if any.

Currently, only RPCs take options. For language requests, assign option a value of CS_UNUSED.

The following symbolic values are legal for option when type is CS_RPC_CMD:

Value

Meaning

CS_RECOMPILE (188)

Recompile the stored procedure before executing it.

CS_NORECOMPILE (189)

Do not recompile the stored procedure before executing it.

CS_UNUSED (-99999)

No options are assigned.

Returns

ct_command returns one of the following values:

Value

Meaning

CS_SUCCEED (-1)

The routine completed successfully.

CS_FAIL (-2)

The routine failed.

TDS_CONNECTION_TERMINATED (-4997)

The connection is not active.

TDS_INVALID_PARAMETER (-4)

A parameter contains an illegal value.

TDS_WRONG_STATE (-6)

Program is in the wrong communication state to issue this call.

Examples

Example 1

The following code fragment demonstrates the use of ct_command. It is taken from the sample program SYCTSAA6 in Appendix A, “Sample Language Application.”

/*-----------------------------------------------------------------*/
/* Open connection to the server or CICS region                    */
/*-----------------------------------------------------------------*/
  
         rc = ct_connect (connection, servname, server_size);
  
         if (rc != CS_SUCCEED)
         {
            strncpy (msgstr, "CT_CONNECT failed", msg_size);
            no_errors_sw = FALSE ;
            error_out (rc);
         }
  /*------------------------------------------------------------*/
  /* Invokes SEND_COMMAND routine                               */
  /*------------------------------------------------------------*/
         if (no_errors_sw)
            send_command ();
  
  /*------------------------------------------------------------*/
  /* Process the results of the command                         */
  /*------------------------------------------------------------*/
         if (no_errors_sw)
         {
            while (no_more_results == FALSE)
               proces_results ();
         }
  }   /* end proces_input */
  /********************************************************************/
  /*                                                                  */
  /* Subroutine to allocate, send, and process commands               */
  /*                                                                  */
  /********************************************************************/
  void send_command ()
  {
   CS_INT        rc;
   CS_INT        *outlen;
   CS_INT        buf_len;
   CS_CHAR       sql_cmd[45];
  
  /*------------------------------------------------------------*/
  /* Find out what the maximum number of connections is         */
  /*------------------------------------------------------------*/
          rc = ct_config (context, CS_GET, CS_MAX_CONNECT,
                         &maxconnect, CS_FALSE, outlen);
          if (rc != CS_SUCCEED)
         {
            strncpy (msgstr, "CT_CONFIG failed", msg_size);
            strncpy (msgtext2, "Please press return to
            continue!",text_size);
            error_out(rc);
  
            /* reset program flags to move on with the task */
            print_once = TRUE;
            diag_msgs_initialized = TRUE;
            strncpy(msgtext2, "Press Clear To Exit", text_size);
         }
  /*------------------------------------------------------------*/
  /* Allocate a command handle                                  */
  /*------------------------------------------------------------*/
           rc = ct_cmd_alloc (connection, &cmd);
  
         if (rc != CS_SUCCEED)
         {
            strncpy (msgstr, "CT_CMDALLOC failed", msg_size);
            no_errors_sw = FALSE ;
            error_out(rc);
         }
  
  	/*------------------------------------------------------------*/
  	/* Prepare the language request                               */
  	/*------------------------------------------------------------*/
         strcpy(sql_cmd,
                 "SELECT FIRSTNME, EDUCLVL FROM SYBASE.SAMPLETB");
           buf_len = sizeof(sql_cmd);
           rc = ct_command(cmd, (long) CS_LANG_CMD, sql_cmd,
                         buf_len, (long) CS_UNUSED);
  
         if (rc != CS_SUCCEED)
         {
            strncpy (msgstr, "CT_COMMAND failed", msg_size);
            no_errors_sw = FALSE ;
            error_out (rc);
         }
  
  /*------------------------------------------------------------*/
  /* Send the language request                                  */
  /*------------------------------------------------------------*/
  
         rc = ct_send (cmd);
  
         if (rc != CS_SUCCEED)
         {
            strcpy (msgstr, "CT_SEND failed", msg_size);
            no_errors_sw = FALSE ;
            error_out (rc);
         }
  }   /* end send_command */

Usage


Language requests


Remote Procedure Calls (RPCs)

See also

Related functions

Related topics