The Microsoft® SQL Server™ ODBC driver exposes driver-specific descriptor fields for the implementation row descriptor (IRD) only. Within the IRD, SQL Server descriptor fields are referenced through driver-specific column attributes. For information about a complete list of available driver-specific descriptor fields, see SQLColAttribute.
Descriptor fields that contain column identifier strings are often zero length strings. For a description of the behavior of ODBC descriptor fields that contain column identifier strings, see SQLColAttribute.
All SQL Server-specific descriptor field values are read-only.
Like attributes retrieved with SQLColAttribute, descriptor fields that report row-level attributes (such as SQL_CA_SS_COMPUTE_ID) are reported for all columns in the result set.
...
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("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("Col in ORDER BY, pos: %ld",
nOrderID);
}
printf("\n");
}
printf("\n");
}
else
{
PCOMPUTEBYLIST pByList;
SQLSMALLINT nBy;
SQLINTEGER nColID;
printf("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("Clause ordered by columns: ");
for (nBy = 0; nBy < pByList->nBys; )
{
printf("%u", pByList->aByList[nBy]);
nBy++;
if (nBy == pByList->nBys)
{
printf("\n");
}
else
{
printf(", ");
}
}
}
else
{
printf("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("ColumnID: %lu, nColID);
}
printf("\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);
}
// and carry on...