dbcoltype

Returns the datatype for a regular result column.

Syntax

INT dbcoltype (
PDBPROCESS
dbproc,
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.
column
Is the number of the column. The first column is number 1. For further information, see "dbadata."

Returns

A value for the datatype for the particular column. If the column is not in range,
-1 is returned.

Column
datatype

Returned constant
char SQLCHAR
varchar SQLCHAR
binary SQLBINARY
varbinary SQLBINARY
tinyint SQLINT1
smallint SQLINT2
int SQLINT4
real SQLFLT4
float SQLFLT8
smallmoney SQLMONEY4
money SQLMONEY
decimal SQLDECIMAL
numeric SQLNUMERIC
smalldatetime SQLDATETIM4
datetime SQLDATETIME
image SQLIMAGE
text SQLTEXT

Remarks

The dbcoltype function returns an integer value for the type. Use dbprtype to convert the type value into a readable string. For a list of SQL Server types, see DB-Library Datatypes. Call dbcoltype after dbresults returns SUCCEED.

This function cannot determine whether a column can take null values.

Example

This example shows how to use dbcoltype and dbprtype:

DBPROCESS    *dbproc;
int            colnum;
int            coltype;

// Put the command into the command buffer. 
dbcmd(dbproc, "select name, id, type from sysobjects");

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

// Process the command results. 
dbresults(dbproc);
// Examine the column types. 
for (colnum = 1; colnum < 4; colnum+)
{
    coltype = dbcoltype(dbproc, colnum);
    printf("column %d, type is %s.\n", colnum, dbprtype(coltype));
}

See Also

dbcollen, dbcolname, dbdata, dbdatlen, dbnumcols, dbprtype; DB-Library Datatypes