Return the maximum length of the data in a regular result column.
DBINT dbcollen(dbproc, column) DBPROCESS *dbproc; int column;
A pointer to the DBPROCESS structure that provides the connection for a particular front-end/server process. It contains all the information that DB-Library uses to manage communications and data between the front end and server.
The number of the column of interest. The first column is number 1.
The maximum length, in bytes, of the data for the particular column. If the column number is not in range, dbcollen returns -1.
This routine returns the maximum length of the data in a regular (that is, non-compute) result column. In the case of variable length data, this is not necessarily the actual length of the data, but rather the maximum length that the data can be. For the actual data length, use dbdatlen.
The value that dbcollen returns is not affected by Transact-SQL string functions such as rtrim and ltrim. For example, if the column au_lname has a maximum length of 20 characters, and the first row instance of au_lname is “Goodman ” (a value padded with 13 spaces), dbcollen returns 20 as the length of au_lname, even though the Transact-SQL command select rtrim(au_lname) from authors returns a string that is 5 characters long.
Here is a small program fragment that uses dbcollen:
DBPROCESS *dbproc;
int colnum;
DBINT column_length;
/* Put the command into the command buffer */
dbcmd(dbproc, "select name, id, type from
sysobjects");
/*
** Send the command to Adaptive Server Enterprise and begin
** execution
*/
dbsqlexec(dbproc);
/* process the command results */
dbresults(dbproc);
/* examine the column lengths */
for (colnum = 1; colnum < 4; colnum++)
{
column_length = dbcollen(dbproc, colnum);
printf("column %d, length is %ld.\n", colnum,
column_length);
}