dbadlen

DB Library for C

DB Library for C

dbadlen

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

Syntax

DBINT dbadlen (
PDBPROCESS
dbproc,
INT
computeid,
INT
column );

Arguments

dbproc

Is the DBPROCESS structure that is the handle for a particular workstation or Microsoft® SQL Server™ 2000 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.

Examples

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

dbgetrow

dbaltlen

dbnextrow

dbalttype

dbnumalts