Export (0) Print
Expand All

SQLGetDescField

The SQL Server Native Client 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. 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.

SQLGetDescField can be used to get values for extended attributes of table-valued parameters and table-valued parameter columns. For more information about table-valued parameters, see Table-Valued Parameters (ODBC).

For information about the descriptor fields available with the new date/time types, see Parameter and Result Metadata.

For more information, see Date/Time Improvements (ODBC).

Beginning in SQL Server 2012, SQLGetDescField can return SQL_C_SS_TIME2 (for time types) or SQL_C_SS_TIMESTAMPOFFSET (for datetimeoffset) instead of SQL_C_BINARY, if your application uses ODBC 3.8.

SQLGetDescField supports large CLR user-defined types (UDTs). For more information, see Large CLR User-Defined Types (ODBC).

SQLGetDescField can be used to query the new IRD field SQL_CA_SS_IS_COLUMN_SET to determine if a column is a column_set column.

For more information, see Sparse Columns Support (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);
    }
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft