SQLGetDescField
SQL Server Native Client ODBC 驱动程序仅公开实现行描述符 (IRD) 的特定于驱动程序的描述符字段。在 IRD 中,通过特定于驱动程序的列属性来引用 SQL Server 描述符字段。有关特定于驱动程序的可用描述符字段的完整列表,请参阅 SQLColAttribute。
包含列标识符字符串的描述符字段通常是长度为零的字符串。特定于 SQL Server 的所有描述符字段值都是只读的。
与使用 SQLColAttribute 检索的属性类似,报告行级属性(如 SQL_CA_SS_COMPUTE_ID)的描述符字段将针对结果集中的所有列进行报告。
SQLGetDescField 对大型 CLR UDT 的支持
SQLGetDescField 支持大型 CLR 用户定义类型 (UDT)。有关详细信息,请参阅大型 CLR 用户定义类型 (ODBC)。
SQLGetDescField 对稀疏列的支持
SQLGetDescField 可用于查询新的 IRD 字段 SQL_CA_SS_IS_COLUMN_SET,以确定列是否为 column_set 列。
有关详细信息,请参阅稀疏列支持 (ODBC)。
示例
typedef struct tagCOMPUTEBYLIST
{
SQLSMALLINT nBys;
SQLSMALLINT aByList[1];
} COMPUTEBYLIST;
typedef COMPUTEBYLIST* PCOMPUTEBYLIST;
SQLHDESC hIRD;
SQLINTEGER cbIRD;
SQLINTEGER nSet = 0;
// . . .
// Execute a statement that contains a COMPUTE clause,
// then get the descriptor handle of the IRD and
// get some IRD values.
SQLGetStmtAttr(g_hStmt, SQL_ATTR_IMP_ROW_DESC,
(SQLPOINTER) &hIRD, sizeof(SQLHDESC), &cbIRD);
// For statement-wide column attributes, any
// descriptor record will do. You know that 1 exists,
// so use it.
SQLGetDescField(hIRD, 1, SQL_CA_SS_NUM_COMPUTES,
(SQLPOINTER) &nComputes, SQL_IS_INTEGER, &cbIRD);
if (nSet == 0)
{
SQLINTEGER nOrderID;
printf_s("Normal result set.\n");
for (nCol = 0; nCol < nCols; nCol++)
{
SQLGetDescField(hIRD, nCol+1,
SQL_CA_SS_COLUMN_ORDER,
(SQLPOINTER) &nOrderID, SQL_IS_INTEGER,
&cbIRD);
if (nOrderID != 0)
{
printf_s("Col in ORDER BY, pos: %ld",
nOrderID);
}
printf_s("\n");
}
printf_s("\n");
}
else
{
PCOMPUTEBYLIST pByList;
SQLSMALLINT nBy;
SQLINTEGER nColID;
printf_s("Computed result set number: %lu\n",
nSet);
SQLGetDescField(hIRD, 1, SQL_CA_SS_COMPUTE_BYLIST,
(SQLPOINTER) &pByList, SQL_IS_INTEGER,
&cbIRD);
if (pByList != NULL)
{
printf_s("Clause ordered by columns: ");
for (nBy = 0; nBy < pByList->nBys; )
{
printf_s("%u", pByList->aByList[nBy]);
nBy++;
if (nBy == pByList->nBys)
{
printf_s("\n");
}
else
{
printf_s(", ");
}
}
}
else
{
printf_s("Compute clause set not ordered.\n");
}
for (nCol = 0; nCol < nCols; nCol++)
{
SQLGetDescField(hIRD, nCol+1,
SQL_CA_SS_COLUMN_ID, (SQLPOINTER) &nColID,
SQL_IS_INTEGER, &cbIRD);
printf_s("ColumnID: %lu, nColID);
}
printf_s("\n");
}
if (SQLMoreResults(g_hStmt) == SQL_SUCCESS)
{
// Determine the result set indicator.
SQLGetDescField(hIRD, 1, SQL_CA_SS_COMPUTE_ID,
(SQLPOINTER) &nSet, SQL_IS_INTEGER, &cbIRD);
}