srv_senddone

Description

Send a results completion message or flush results to a client.

Syntax

CS_RETCODE srv_senddone(spp, status, transtate, count)
SRV_PROC         *spp;
CS_INT                status;
CS_INT                transtate;
CS_INT              count;

Parameters

spp

A pointer to an internal thread control structure.

status

A 2-byte bit mask composed of one or more flags OR’d together. Table 3-117 describes each flag:

Table 3-117:  Values for status (srv_senddone)

Status

Description

SRV_DONE_FINAL

The current set of results is the final set of results.

SRV_DONE_MORE

The current set of results is not the final set of results.

SRV_DONE_COUNT

The count parameter contains a valid count.

SRV_DONE_ERROR

The current client command got an error.

SRV_DONE_FLUSH

The current result set will be sent to the client without waiting for a full packet.

transtate

The current state of the transaction. Table 3-118 describes the legal values for transtate:

Table 3-118:  Values for transtate (srv_senddone)

Transaction State

Description

CS_TRAN_UNDEFINED

Not currently in a transaction.

CS_TRAN_COMPLETED

The current transaction completed successfully.

CS_TRAN_FAIL

The current transaction failed.

CS_TRAN_IN_PROGRESS

Currently in a transaction.

CS_TRAN_STMT_FAIL

The current transaction statement failed.

count

A 4-byte field containing a count for the current set of results. The count is valid if the SRV_DONE_COUNT flag is set in the status field.

Returns

Table 3-119:  Return values (srv_senddone)

Returns

To indicate

CS_SUCCEED

The routine completed successfully.

CS_FAIL

The routine failed.

Examples

Example 1

#include     <ospublic.h>

/*
** Local Prototype.
*/
CS_RETCODE      ex_srv_senddone PROTOTYPE((
SRV_PROC        *spp
));

/*
** Constants and data definitions.
*/
#define    NUMROWS         3  
#define    MAXROWDATA      6

CS_STATIC CS_CHAR  *row_data[NUMROWS] = {
                    “Larry”,
                    “Curly”,
                    “Moe”
                    };

/*
** EX_SRV_SENDDONE
**
**    Example routine illustrating the use of srv_senddone. This
 **    routine will send a set of results to the client
 **    application, and then send the results completion message.
**
** Arguments:
**    spp     A pointer to an internal thread control structure.
**
** Returns:
**    CS_SUCCEED    Results set sent successfully to client.
**    CS_FAIL       An error was detected.
*/
CS_RETCODE      ex_srv_senddone(spp)
SRV_PROC        *spp;
{
      CS_DATAFMT      fmt;
      CS_INT          row_len;
      CS_INT          idx;

      /*
      ** Describe the format of the row data, with the single
       ** dummy column.
      */
      srv_bzero((CS_VOID *)&fmt, (CS_INT)sizeof(fmt));
      fmt.datatype = CS_CHAR_TYPE;
      fmt.maxlength = MAXROWDATA;

      if (srv_descfmt(spp, (CS_INT)CS_SET, (CS_INT)SRV_ROWDATA,
                (CS_INT)1, &fmt) != CS_SUCCEED)
      {
             (CS_VOID)srv_senddone(spp,
                (CS_INT)(SRV_DONE_FINAL | SRV_DONE_ERROR),
                (CS_INT)CS_TRAN_FAIL, (CS_INT)0);
             return(CS_FAIL);
       }

      for (idx = 0; idx < NUMROWS; ++idx)
      {
           /*
           ** Bind the row_data array element. 
           */
           row_len = (CS_INT)strlen(row_data[idx]);
           if (srv_bind(spp, (CS_INT)CS_SET, (CS_INT)SRV_ROWDATA,
               (CS_INT)1, &fmt, (CS_BYTE *)(row_data[idx]),
                &row_len, (CS_SMALLINT *)NULL) != CS_SUCCEED)
       
           {
                /* Communicate failure, and number of rows sent. */
                (CS_VOID)srv_senddone(spp,
                     (CS_INT)(SRV_DONE_FINAL |
                              SRV_DONE_ERROR | SRV_DONE_COUNT),
                     (CS_INT)CS_TRAN_FAIL, (CS_INT)idx);
                return(CS_FAIL);
           }

           /*
           ** Transfer the row data.
           */
           if (srv_xferdata(spp, (CS_INT)CS_SET, SRV_ROWDATA)
                                 != CS_SUCCEED)
           {
                /* Communicate failure, and number of rows sent. */
                (CS_VOID)srv_senddone(spp,
                    (CS_INT)(SRV_DONE_FINAL |
                        SRV_DONE_ERROR | SRV_DONE_COUNT),
                    (CS_INT)CS_TRAN_FAIL, (CS_INT)idx);
                return(CS_FAIL);
            }
      }

      /* Send a status value. */
      if (srv_sendstatus(spp, (CS_INT)0) != CS_SUCCEED)
      {
            /* Communicate failure, and number of rows sent. */
            (CS_VOID)srv_senddone(spp,
                (CS_INT)(SRV_DONE_FINAL |
                    SRV_DONE_ERROR | SRV_DONE_COUNT),
                (CS_INT)CS_TRAN_FAIL, (CS_INT)NUMROWS);
            return(CS_FAIL);
      }

      /* Send the final DONE message, with the row count. */
      if (srv_senddone(spp, (CS_INT)(SRV_DONE_FINAL | 
             SRV_DONE_COUNT),
                (CS_INT)CS_TRAN_COMPLETED,
                (CS_INT)NUMROWS) != CS_SUCCEED)
      {
            /* Communicate failure, and number of rows sent. */
            (CS_VOID)srv_senddone(spp,
                (CS_INT)(SRV_DONE_FINAL |
                        SRV_DONE_ERROR | SRV_DONE_COUNT),
                (CS_INT)CS_TRAN_FAIL, (CS_INT)NUMROWS);
            return(CS_FAIL);
      }
return(CS_SUCCEED);
}

Usage

NoteThe transtate argument replaces the info argument in the Open Server 2.0 version of srv_senddone.This change will cause runtime errors in existing applications if the value of info in the existing application is not 0.

See also

srv_bind, srv_descfmt, srv_sendstatus, srv_xferdata