ct_res_info  ct_send

Chapter 3: Functions

ct_results

Description

Sets up result data to be processed.

Syntax

CS_RETCODE    ct_results(command, result_type);
CS_COMMAND    *command;
CS_INT        *result_type;

Parameters

command

(I) Handle for this client/server operation. This handle is defined in the associated ct_cmd_alloc call.

result_type

(O) Variable containing the result type. ct_results returns to this variable a symbolic value that indicates the type of result returned by the current request. The result type can be any of the following symbolic values listed in Table 3-15.

Table 3-15: Values for result_type (ct_results)

Value

Meaning

Result produced

CS_ROW_RESULT (4040)

Regular row results arrived.

One or more rows of tabular data.

CS_PARAM_RESULT (4042)

Return parameter results arrived.

A single row of return parameters.

CS_STATUS_RESULT (4043)

Stored procedure return status results arrived.

A single row containing a single status.

CS_CMD_DONE (4046)

The results of the request processed completely.

Not applicable.

CS_CMD_SUCCEED (4047)

A request that returns no data, such as a language request containing an insert statement, processed successfully.

No results.

CS_CMD_FAIL (4048)

The server encountered an error while executing the request. This value can indicate that the connection failed or was terminated.

No results.

Returns

ct_results returns one of the following values:

Value

Meaning

CS_SUCCEED (-1)

A result set is available for processing.

CS_END_RESULTS (-205)

No more result sets are available for processing.

CS_FAIL (-2)

The routine failed.

CS_CANCELLED (-202)

Results were canceled.

Examples

Example 1

The following code fragment demonstrates how ct_results can describe a result row for a language request. It is taken from the sample program SYCTSAA6 in Appendix A, “Sample Language Application.”

  	/********************************************************************/
  	/*                                                                  */
  	/* Subroutine to process the result                                 */
  	/*                                                                  */
  	/********************************************************************/
  	void   proces_results ()
  
  	{
   CS_INT        rc;
  
  /*------------------------------------------------------------*/
  /* Set up the results data                                    */
  /*------------------------------------------------------------*/
  
         rc = ct_results (cmd, &results_type);
  
  /*------------------------------------------------------------*/
  /* Determine the outcome of the comand execution              */
  /*------------------------------------------------------------*/
  
         switch (rc)
         {
            case CS_SUCCEED:
  
  /*--------------------------------------------------------------*/
  /* Determine the type of result returned by the current request */
  /*--------------------------------------------------------------*/
  
                 switch (results_type)
                 {
  
  /*------------------------------------------------------------*/
  /* Process row results                                        */
  /*------------------------------------------------------------*/
  
                    case CS_ROW_RESULT:
                         result_row_processing ();
                         fetch_row_processing ();
                         break;
  /*------------------------------------------------------------*/
  /* Process parameter results --- there should be no parameter */
  /* to process                                                 */
  /*------------------------------------------------------------*/
                    case CS_PARAM_RESULT:
                         no_more_results = FALSE;
                         break;
  
  /*------------------------------------------------------------*/
  /* process status results --- the stored procedure status     */
  /* result will not be processed in this example               */
  /*------------------------------------------------------------*/
                    case CS_STATUS_RESULT:
                         no_more_results = FALSE;
                         break;
  /*------------------------------------------------------------*/
  /* print an error message if the server encountered an error  */
  /* while executing the request                                */
  /*------------------------------------------------------------*/
  
                    case CS_CMD_FAIL:
                         no_errors_sw = FALSE ;
                         strncpy (msgstr,
                           "CT_RESUL returned CS_CMD-FAIL restype",
                         msg_size);
                         error_out (rc);
                         break;
  /*------------------------------------------------------------*/
  /* print a message for successful commands that returned no   */
  /* data( optional )                                           */
  /*------------------------------------------------------------*/
                    case CS_CMD_SUCCEED:
                         strncpy (msgstr,
                           "CT_RESUL returned CS_CMD_SUCCEED restype",
                         msg_size);
                         break;
  /*------------------------------------------------------------*/
  /* print a message for requests that have been processed      */
  /* successfully( optional )                                   */
  /*------------------------------------------------------------*/
                    case CS_CMD_DONE:
                         strncpy (msgstr,
                         "CT_RESUL returned CS_CMD_DONE restype",
                         msg_size);
                         break;
  
                    default:
                         no_more_results = TRUE ;
                         no_errors_sw    = FALSE ;
                         strncpy (msgstr,
                           "CT_RESUL returned UNKNOWN restype",
                         msg_size);
                         error_out (rc);
                         break;
  
                 }   /* end of switch (result_type) */
                 break;   /* case of CS_SUCCEED  */
  /*------------------------------------------------------------*/
  /* print an error message if the CTBRESULTS call failed       */
  /*------------------------------------------------------------*/
            case CS_FAIL:
                 no_more_results = TRUE ;
                 no_errors_sw    = FALSE ;
                 strncpy (msgstr, "CT_RESULTS returned CS_FAIL ret_code",
                          msg_size);
                 error_out (rc);
                 break;
  /*------------------------------------------------------------*/
  /* drop out of the results loop if no more result sets are    */
  /* available for processing or if the results were cancelled  */
  /*------------------------------------------------------------*/
            case CS_END_RESULTS:
            case CS_CANCELLED:
                 no_more_results = TRUE ;
                 break;
  
            default:
                 no_more_results = TRUE ;
                 no_errors_sw    = FALSE ;
                 strncpy (msgstr, "CT_RESULTS returned unknown ret_code",
                          msg_size);
                 error_out (rc);
                 break;
  
         }  /* end of switch (rc) */
  
  }   /* end process_results */

Usage


The ct_results loop


When are the results of a command completely processed?


Canceling results


ct_results and stored procedures

See also

Related functions

Related topics





Copyright © 2005. Sybase Inc. All rights reserved. ct_send

View this book as PDF