You can use SQLColAttribute to retrieve an attribute of a result set column for either prepared or executed ODBC statements. Calling SQLColAttribute on prepared statements causes a roundtrip to the Microsoft® SQL Server™. The SQL Server ODBC driver receives result set column data as part of statement execution, so calling SQLColAttribute after the completion of SQLExecute or SQLExecDirect does not involve a server roundtrip.
ODBC column identifier attributes are not available on all SQL Server result sets.
FieldIdentifier value | Description |
---|---|
SQL_COLUMN_TABLE_NAME | Available on result sets retrieved from statements that generate server cursors or on executed SELECT statements containing a FOR BROWSE clause. |
SQL_DESC_BASE_COLUMN_NAME | Available on result sets retrieved from statements that generate server cursors or on executed SELECT statements containing a FOR BROWSE clause. |
SQL_DESC_BASE_TABLE_NAME | Available on result sets retrieved from statements that generate server cursors or on executed SELECT statements containing a FOR BROWSE clause. |
SQL_DESC_CATALOG_NAME | Database name. Available on result sets retrieved from statements that generate server cursors or on executed SELECT statements containing a FOR BROWSE clause. |
SQL_DESC_LABEL | Available on all result sets. The value is identical to the value of the SQL_DESC_NAME field.
The field is zero length only if a column is the result of an expression and the expression does not contain a label assignment. |
SQL_DESC_NAME | Available on all result sets. The value is identical to the value of the SQL_DESC_LABEL field.
The field is zero length only if a column is the result of an expression and the expression does not contain a label assignment. |
SQL_DESC_SCHEMA_NAME | Owner name. Available on result sets retrieved from statements that generate server cursors or on executed SELECT statements containing a FOR BROWSE clause.
Available only if the owner name is specified for the column in the SELECT statement. |
SQL_DESC_TABLE_NAME | Available on result sets retrieved from statements that generate server cursors or on executed SELECT statements containing a FOR BROWSE clause. |
SQL_DESC_UNNAMED | SQL_NAMED for all columns in a result set unless a column is the result of an expression that does not contain a label assignment as part of the expression. When SQL_DESC_UNNAMED returns SQL_UNNAMED, all ODBC column identifier attributes contain zero length strings for the column. |
Note When connected to SQL Server 4.2x, SQLColAttribute must create a result set to report column attributes. The SQL Server ODBC driver appends the clause WHERE 1 = 2 to prepared SELECT statements prior to execution. When connected to SQL Server 4.2x, SQLColAttribute cannot return information about a result set that is generated by a procedure if that procedure has been prepared but not executed.
When connected to any later version of SQL Server, the SQL Server ODBC driver uses the SET FMTONLY statement to reduce server overhead when SQLColAttribute is called for prepared but unexecuted statements.
For all versions, column attributes are reported for only the first result set when multiple result sets are generated by a prepared batch of SQL statements.
The following column attributes are extensions exposed by the SQL Server ODBC driver. The SQL Server ODBC driver returns all values in the NumericAttrPtr parameter. The values are returned as SDWORD (signed long) except SQL_CA_SS_COMPUTE_BYLIST, which is a pointer to a WORD array.
FieldIdentifier value | Value returned |
---|---|
SQL_CA_SS_COLUMN_HIDDEN* | TRUE if the column referenced is part of a hidden primary key created to support a Transact-SQL SELECT statement containing FOR BROWSE. |
SQL_CA_SS_COLUMN_ID | Ordinal position of a COMPUTE clause result column within the current Transact-SQL SELECT statement. |
SQL_CA_SS_COLUMN_KEY* | TRUE if the column referenced is part of a primary key for the row and the Transact-SQL SELECT statement contains FOR BROWSE. |
SQL_CA_SS_COLUMN_OP | Integer specifying the aggregate operator responsible for the value in a COMPUTE clause column. Definitions of the integer values are in Odbcss.h. |
SQL_CA_SS_COLUMN_ORDER | Ordinal position of the column within an ODBC or Transact-SQL SELECT statement’s ORDER BY clause. |
SQL_CA_SS_COLUMN_SIZE | Maximum length, in bytes, required to bind a data value retrieved from the column to a SQL_C_BINARY variable. |
SQL_CA_SS_COLUMN_SSTYPE | Native data type of data stored in the SQL Server column. Definitions of the type values are in Odbcss.h. |
SQL_CA_SS_COLUMN_UTYPE | Base data type of the SQL Server column’s user-defined data type. Definitions of the type values are in Odbcss.h. |
SQL_CA_SS_COLUMN_VARYLEN | TRUE if the column’s data can vary in length, FALSE otherwise. |
SQL_CA_SS_COMPUTE_BYLIST | Pointer to an array of WORD (unsigned short) specifying the columns used in the BY phrase of a COMPUTE clause. If the COMPUTE clause does not specify a BY phrase, a NULL pointer is returned.
The first element of the array contains the count of BY list columns. Additional elements are the column ordinals. |
SQL_CA_SS_COMPUTE_ID | computeid of a row that is the result of a COMPUTE clause in the current Transact-SQL SELECT statement. |
SQL_CA_SS_NUM_COMPUTES | Number of COMPUTE clauses specified in the current Transact-SQL SELECT statement. |
SQL_CA_SS_NUM_ORDERS | Number of columns specified in an ODBC or Transact-SQL SELECT statement’s ORDER BY clause. |
* Available if statement attribute SQL_SOPT_SS_HIDDEN_COLUMNS is set to SQL_HC_ON. |