dbcoltype

Returns the data type for a regular result column.

Syntax

INT dbcoltype (
PDBPROCESS
dbproc,
INT
column );

Arguments
dbproc
Is the DBPROCESS structure that is the handle for a particular workstation/ Microsoft® 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 data type for the particular column. If the column is not in range,
-1 is returned.

Column data type 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 more information about a list of SQL Server types, see DB-Library for C Data Types. Call dbcoltype after dbresults returns SUCCEED.

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

Examples

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 DB-Library for C Data Types
dbcolname dbnumcols
dbdata dbprtype
dbdatlen  

  


(c) 1988-98 Microsoft Corporation. All Rights Reserved.