Retrieve compute result information.
CS_RETCODE ct_compute_info(cmd, type, colnum, buffer, buflen, outlen) CS_COMMAND *cmd; CS_INT type; CS_INT colnum; CS_VOID *buffer; CS_INT buflen; CS_INT *outlen;
A pointer to the CS_COMMAND structure managing a client/server command.
The type of information to return. For a list of the symbolic values for type, see Table 3-10.
The number of the compute column of interest, as it appears in the compute row result set. Compute columns appear in the order in which they are listed in the compute clause of a select statement. The first column is number 1, the second is number 2, and so forth.
A pointer to the space in which ct_compute_info will place the requested information.
If buflen indicates that *buffer is not large enough to hold the requested information, ct_compute_info returns CS_FAIL.
The length, in bytes, of the *buffer data space or CS_UNUSED if *buffer represents a fixed-length or symbolic value.
A pointer to an integer variable.
ct_compute_info returns the following values:
Return value |
Meaning |
---|---|
CS_SUCCEED |
The routine completed successfully. |
CS_FAIL |
The routine failed. |
CS_BUSY |
An asynchronous operation is already pending for this connection. See “Asynchronous programming”. |
Assume that the following command has been executed:
select dept, name, year, sales from employee
order by dept, name, year
compute count(name) by dept, name
The call:
CS_INT mybuffer;
ct_compute_info(cmd, CS_BYLIST_LEN, CS_UNUSED,
&mybuffer, CS_UNUSED, CS_UNUSED);
sets mybuffer to 2, because there are two items in the bylist.
The call:
CS_SMALLINT mybuffer[2];
CS_INT outlength;
ct_compute_info(cmd, CS_COMP_BYLIST, CS_UNUSED,
mybuffer, sizeof(mybuffer), &outlength)
copies the CS_SMALLINT values 1 and 2 into mybuffer[0] and mybuffer[1] to indicate that the bylist is composed of columns 1 and 2 from the select list.
The call:
CS_INT mybuffer;
ct_compute_info(cmd, CS_COMP_COLID, 1, &mybuffer,
CS_UNUSED,NULL);
sets mybuffer to 2, since name is the second column in the select list.
The call:
CS_INT mybuffer;
ct_compute_info(cmd, CS_COMP_ID, CS_UNUSED,
&mybuffer, CS_UNUSED, NULL);
sets mybuffer to 1 because there is only a single compute clause in the select statement.
The call:
CS_INT mybuffer;
ct_compute_info(cmd, CS_COMP_OP, 1, &mybuffer,
CS_UNUSED, NULL);
sets mybuffer to the symbolic value CS_OP_COUNT, since the aggregate operator for the first compute column is a count.
Table 3-10 summarizes ct_compute_info usage.
Value of type |
Value of colnum |
Information retrieved |
*buffer is set to |
*outlen is set to |
---|---|---|---|---|
CS_BYLIST_LEN |
CS_UNUSED |
The number of elements in the bylist array |
An integer valu. |
sizeof(CS_INT) |
CS_COMP_BYLIST |
CS_UNUSED |
An array containing the bylist that produced this compute row |
An array of CS_SMALLINT values |
The length of the array, in bytes |
CS_COMP_COLID |
The column number of the compute column |
The select-list column ID of the column from which the compute column derives |
An integer value |
sizeof(CS_INT) |
CS_COMP_ID |
CS_UNUSED |
The compute ID for the current compute row |
An integer value |
sizeof(CS_INT) |
CS_COMP_OP |
The column number of the compute column |
The aggregate operator type for the compute column |
One of the following symbolic values: CS_OP_SUM CS_OP_AVG CS_OP_COUNT CS_OP_MIN CS_OP_MAX |
sizeof(CS_INT) |
Compute rows result from the compute clause of a select statement. A compute clause generates a compute row every time the value of its by column-list changes. A compute row contains one column for each aggregate operator in the compute clause. If a select statement contains multiple compute clauses, separate compute rows are generated by each clause.
Each compute row returned by the server is considered to be a distinct result set. That is, each result set of type CS_COMPUTE_RESULT will contain exactly one row.
It is only legal to call ct_compute_info when compute information is available; that is, after ct_results returns CS_COMPUTE_RESULT or CS_COMPUTEFMT.
Each section below contains information about a particular type of compute result information.
A select statement’s compute clause may contain the keyword by, followed by a list of columns. This list, known as the bylist, divides the results into subgroups, based on changing values in the specified columns. The compute clause’s aggregate operators are applied to each subgroup, generating a compute row for each subgroup.
The select-list column ID for a compute column is the position within the select-list of the column from which the compute column derives.
A SQL select statement can have multiple compute clauses, each of which returns a separate compute row. The compute ID corresponding to the first compute clause in a select statement is 1.
When called with type as CS_COMP_OP,ct_compute_info sets *buffer to one of the following aggregate operator types:
*buffer setting |
Meaning |
---|---|
CS_OP_AVG |
Average aggregate operator |
CS_OP_COUNT |
Count aggregate operator |
CS_OP_MAX |
Maximum aggregate operator |
CS_OP_MIN |
Minimum aggregate operator |
CS_OP_SUM |
Sum aggregate operator. |