dbadata

Returns a pointer to the data for a compute column.

Syntax

LPCBYTE dbadata (
PDBPROCESS
dbproc,
INT
computeid,
INT
column );

where

dbproc
Is the DBPROCESS structure that is the handle for a particular workstation/ SQL Server process. It contains all the information that DB-Library uses to manage communications and data between the workstation and SQL Server.
computeid
Is the ID that identifies the COMPUTE clause. A SELECT statement can have multiple COMPUTE clauses, which can have varying numbers of aggregate operators and aggregate targets. The computeid is returned by dbnextrow or dbgetrow.
column
Is the number of the column. The first column returned is number 1.

Returns

A BYTE pointer to the data for a particular column in a compute. A null BYTE pointer is returned if there is no such column or compute or if the data has a null value. The data space pointed to is allocated and freed by DB-Library. Be careful not to overwrite the space.

Remarks

After each call to dbnextrow that returns a value greater than 0, use dbadata to obtain a pointer to the data for a particular column in a compute. The data is not null-terminated. Use dbadlen to get the length of the data.

When a column of integer data is summed or averaged, SQL Server always returns a four-byte integer, regardless of the size of the column. Therefore, be sure that the variable that is to contain the result from such a compute is declared as DBINT.

Example

The following program fragment shows how to use dbadata:

DBPROCESS    *dbproc;
int            rowinfo;
DBINT        sum;

// First, put the commands into the command buffer. 
dbcmd(dbproc, "select db_name(dbid), dbid, size from sysusages");
dbcmd(dbproc, " order by dbid");
dbcmd(dbproc, " compute sum(size) by dbid");
// Send the commands to SQL Server and start execution. 
dbsqlexec(dbproc);
// Process the command. 
dbresults(dbproc);
// Examine the results of the COMPUTE clause. 
while((rowinfo = dbnextrow(dbproc)) != NO_MORE_ROWS)
{
    if (rowinfo == REG_ROW)
        printf("regular row returned.\n");
    else
    {
        // This row is the result of a COMPUTE clause,
        // and "rowinfo" is the computeid of this COMPUTE
        // clause.
         
        sum = *(DBINT *)(dbadata(dbproc, rowinfo, 1));
        printf("sum = %ld\n", sum);
    }
}

The dbaltbind function automatically binds data to your program variables. It is somewhat easier to use than dbadata and dbadlen but is less efficient because it copies the data into your variable.

See Also

dbadlen, dbaltbind, dbaltlen, dbalttype, dbgetrow, dbnextrow, dbnumalts