dbadlen

Returns the actual length of the data for a compute column.

Syntax

DBINT dbadlen (
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 is number 1.

Returns

The length, in bytes, of the data for a compute column. When no such column or COMPUTE clause exists, -1 is returned. When the data has a null value, 0 is returned.

Remarks

This dbadlen returns the length of the data for a compute column. You can get a pointer to the actual data by using dbadata. Calling dbadata after dbnextrow or dbgetrow returns a computeid.

Example

The following program fragment shows how to use dbadlen:

DBPROCESS    *dbproc;
char            biggest_name[MAXNAME+1];
DBINT        namelen;
STATUS        rowinfo;

// Put the command into the command buffer. 
dbcmd(dbproc, "select name from sysobjects");
dbcmd(dbproc, " order by name");
dbcmd(dbproc, " compute max(name)");

// Send the command to SQL Server and start execution. 
dbsqlexec(dbproc);

// Process the command. 
dbresults(dbproc);

// Examine each row returned by the command. 
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.
         

        namelen = dbadlen(dbproc, rowinfo, 1);
        strncpy(biggest_name,(char *)dbadata(dbproc, rowinfo, 1),
            (int)namelen);

        // Data pointed to by dbadata() is not null-terminated. 
        biggest_name[namelen] = '\0';

        printf("biggest name = %s\n", biggest_name);
    }
}

See Also

dbadata, dbaltlen, dbalttype, dbgetrow, dbnextrow, dbnumalts