SQLGetDescRec function (CLI) - Get multiple field settings of descriptor record

Returns the current settings of multiple fields of a descriptor record. The fields returned describe the name, data type, and storage of column or parameter data.

Specification:

  • CLI 5.0
  • ODBC 3.0
  • ISO CLI
Unicode equivalent: This function can also be used with the Unicode character set. The corresponding Unicode function is SQLGetDescRecW(). See Unicode functions (CLI) for information about ANSI to Unicode function mappings.

Syntax

SQLRETURN   SQLGetDescRec (
               SQLHDESC          DescriptorHandle,   /* hDesc */
               SQLSMALLINT       RecNumber,
               SQLCHAR           *Name,
               SQLSMALLINT       BufferLength,
               SQLSMALLINT       *StringLengthPtr,   /* *StringLength */
               SQLSMALLINT       *TypePtr,           /* *Type */
               SQLSMALLINT       *SubTypePtr,        /* *SubType */
               SQLLEN            *LengthPtr,         /* *Length */
               SQLSMALLINT       *PrecisionPtr,      /* *Precision */
               SQLSMALLINT       *ScalePtr,          /* *Scale */
               SQLSMALLINT       *NullablePtr);      /* *Nullable */

Function arguments

Table 1. SQLGetDescRec arguments
Data type Argument Use Description
SQLHDESC DescriptorHandle input Descriptor handle.
SQLSMALLINT RecNumber input Indicates the descriptor record from which the application seeks information. Descriptor records are numbered from 0, with record number 0 being the bookmark record. The RecNumber argument must be less than or equal to the value of SQL_DESC_COUNT. If RecNumber is less than SQL_DESC_COUNT, but the row does not contain data for a column or parameter, a call to SQLGetDescRec() will return the default values of the fields.
SQLCHAR * Name output A pointer to a buffer in which to return the SQL_DESC_NAME field for the descriptor record.
SQLINTEGER BufferLength input Number of SQLCHAR elements (or SQLWCHAR elements for the Unicode variant of this function) needed to store the *Name buffer.
SQLSMALLINT * StringLengthPtr output A pointer to a buffer in which to return the number of SQLCHAR elements (or SQLWCHAR elements for the Unicode variant of this function) available to return in the Name buffer, excluding the null-termination character. If the number of SQLCHAR or SQLWCHAR elements was greater than or equal to BufferLength, the data in *Name is truncated to BufferLength minus the length of a null-termination character, and is null terminated by CLI.
SQLSMALLINT * TypePtr output A pointer to a buffer in which to return the value of the SQL_DESC_TYPE field for the descriptor record.
SQLSMALLINT * SubTypePtr output For records whose type is SQL_DATETIME, this is a pointer to a buffer in which to return the value of the SQL_DESC_DATETIME_INTERVAL_CODE field.
SQLLEN * LengthPtr output A pointer to a buffer in which to return the value of the SQL_DESC_OCTET_LENGTH field for the descriptor record.
SQLSMALLINT * PrecisionPtr output A pointer to a buffer in which to return the value of the SQL_DESC_PRECISION field for the descriptor record.
SQLSMALLINT * ScalePtr output A pointer to a buffer in which to return the value of the SQL_DESC_SCALE field for the descriptor record.
SQLSMALLINT * NullablePtr output A pointer to a buffer in which to return the value of the SQL_DESC_NULLABLE field for the descriptor record.

Usage

An application can call SQLGetDescRec() to retrieve the values of the following fields for a single column or parameter:
  • SQL_DESC_NAME
  • SQL_DESC_TYPE
  • SQL_DESC_DATETIME_INTERVAL_CODE (for records whose type is SQL_DATETIME)
  • SQL_DESC_OCTET_LENGTH
  • SQL_DESC_PRECISION
  • SQL_DESC_SCALE
  • SQL_DESC_NULLABLE

SQLGetDescRec() does not retrieve the values for header fields.

An application can inhibit the return of a field's setting by setting the argument corresponding to the field to a null pointer. When an application calls SQLGetDescRec() to retrieve the value of a field that is undefined for a particular descriptor type, the function returns SQL_SUCCESS but the value returned for the field is undefined. For example, calling SQLGetDescRec() for the SQL_DESC_NAME or SQL_DESC_NULLABLE field of an APD or ARD will return SQL_SUCCESS but an undefined value for the field.

When an application calls SQLGetDescRec() to retrieve the value of a field that is defined for a particular descriptor type, but has no default value and has not been set yet, the function returns SQL_SUCCESS but the value returned for the field is undefined.

The values of fields can also be retrieved individually by a call to SQLGetDescField().

Return codes

  • SQL_SUCCESS
  • SQL_SUCCESS_WITH_INFO
  • SQL_ERROR
  • SQL_NO_DATA
  • SQL_INVALID_HANDLE

SQL_NO_DATA is returned if RecNumber is greater than the number of descriptor records.

SQL_NO_DATA is returned if DescriptorHandle is an IRD handle and the statement in the prepared or executed state, but there was no open cursor associated with it.

Diagnostics

Table 2. SQLGetDescRec SQLSTATEs
SQLSTATE Description Explanation
01000 Warning. Informational message. (Function returns SQL_SUCCESS_WITH_INFO.)
01004 Data truncated. The buffer *Name was not large enough to return the entire descriptor field, so the field was truncated. The length of the untruncated descriptor field is returned in *StringLengthPtr. (Function returns SQL_SUCCESS_WITH_INFO.)
07009 Invalid descriptor index. The RecNumber argument was set to 0 and the DescriptorHandle argument was an IPD handle.

The RecNumber argument was set to 0, and the SQL_ATTR_USE_BOOKMARKS statement attribute was set to SQL_UB_OFF.

The RecNumber argument was less than 0.

08S01 Communication link failure. The communication link between CLI and the data source to which it was connected failed before the function completed processing.
HY000 General error. An error occurred for which there was no specific SQLSTATE. The error message returned by SQLGetDiagRec() in the *MessageText buffer describes the error and its cause.
HY001 Memory allocation failure. Db2® CLI is unable to allocate memory required to support execution or completion of the function. It is likely that process-level memory has been exhausted for the application process. Consult the operating system configuration for information about process-level memory limitations.
HY007 Associated statement is not prepared. DescriptorHandle was associated with an IRD, and the associated statement handle was not in the prepared or executed state.
HY010 Function sequence error. DescriptorHandle was associated with a StatementHandle for which an asynchronously executing function (not this one) was called and was still executing when this function was called.

DescriptorHandle was associated with a StatementHandle for which SQLExecute() or SQLExecDirect() was called and returned SQL_NEED_DATA. This function was called before data was sent for all data-at-execution parameters or columns.

HY013 Unexpected memory handling error. Db2 CLI was unable to access memory required to support execution or completion of the function.

Restrictions

None.

Example

    /* get multiple field settings of descriptor record */
    rc = SQLGetDescRec(hIRD,
                       i,
                       colname,
                       sizeof(colname),
                       &namelen,
                       &type,
                       &subtype,
                       &width,
                       &precision,
                       &scale,
                       &nullable);

    /* ... */
    
    /* get the record/column value after setting */
    rc = SQLGetDescRec(hARD,
                       i,
                       colname,
                       sizeof(colname),
                       &namelen,
                       &type,
                       &subtype,
                       &width,
                       &precision,
                       &scale,
                       &nullable);