srv_orderby

Description

Return an order-by list to a client.

Syntax

CS_RETCODE srv_orderby(spp, numcols, collistp)
SRV_PROC    *spp;
CS_INT           numcols;
CS_INT          *collistp;

Parameters

spp

A pointer to an internal thread control structure.

numcols

The number of columns in the order-by list. Because the columns are passed as an array of CS_INTs, numcols is really the number of elements in the collistp array.

collistp

A pointer to the array of column numbers. The size of this array is numcols.

Returns

Table 3-78: Return values (srv_orderby)

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_orderby PROTOTYPE((
SRV_PROC     *spp
));

/*
** EX_SRV_ORDERBY
**
**    Example routine using srv_orderby to define and return to a 
 **    client application the order-by list for a simple SQL
 **    command.
**    This example uses the SQL command:
**
**        “select a,b,c,d from my_tab
 **         order by c,a”
**
** Arguments:
**    spp    A pointer to the internal thread control structure.
**
** Returns:
**    CS_SUCCEED      Order-by list was successfully defined.
**    CS_FAIL         An error was detected..
*/
CS_RETCODE            ex_srv_orderby(spp)
SRV_PROC              *spp;
{
    /* There are two columns specified in the order-by clause. */
    CS_INT        collist[2];
    CS_INT        numcols;

    /* Initialization. */
    numcols = 2;

    /*
    ** Initialize the collist array in the order the
     ** columns occur in the order-by clause.
    **
    ** “c” is the 1st column specified in the order-by,
     ** and is the 3rd column specified in the select-list.
    */
    collist[0] = (CS_INT)3;
    /*
    ** “a” is the 2nd column specified in the order-by,
     ** and is the 1st column specified in the select-list.
    */
    collist[1] = (CS_INT)1;
    /*
    ** Define the order-by list.
    */
    if (srv_orderby(spp, numcols, collist) != CS_SUCCEED)
    {
        return(CS_FAIL);
    }
    return(CS_SUCCEED);
}

Usage