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 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.
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));
}