SQLSetDescField Function
When SQLSetDescField returns SQL_ERROR or SQL_SUCCESS_WITH_INFO, an associated SQLSTATE value can be obtained by calling SQLGetDiagRec with a HandleType of SQL_HANDLE_DESC and a Handle of DescriptorHandle. The following table lists the SQLSTATE values commonly returned by SQLSetDescField and explains each one in the context of this function; the notation "(DM)" precedes the descriptions of SQLSTATEs returned by the Driver Manager. The return code associated with each SQLSTATE value is SQL_ERROR, unless noted otherwise.
|
SQLSTATE |
Error |
Description |
|---|---|---|
|
01000 |
General warning |
Driver-specific informational message. (Function returns SQL_SUCCESS_WITH_INFO.) |
|
01S02 |
Option value changed |
The driver did not support the value specified in *ValuePtr (if ValuePtr was a pointer) or the value in ValuePtr (if ValuePtr was an integer value), or *ValuePtr was invalid because of implementation working conditions, so the driver substituted a similar value. (Function returns SQL_SUCCESS_WITH_INFO.) |
|
07009 |
Invalid descriptor index |
The FieldIdentifier argument was a record field, the RecNumber argument was 0, and the DescriptorHandle argument referred to an IPD handle. The RecNumber argument was less than 0, and the DescriptorHandle argument referred to an ARD or an APD. The RecNumber argument was greater than the maximum number of columns or parameters that the data source can support, and the DescriptorHandle argument referred to an APD or ARD. (DM) The FieldIdentifier argument was SQL_DESC_COUNT, and *ValuePtr argument was less than 0. The RecNumber argument was equal to 0, and the DescriptorHandle argument referred to an implicitly allocated APD. (This error does not occur with an explicitly allocated application descriptor, because it is not known whether an explicitly allocated application descriptor is an APD or ARD until execute time.) |
|
08S01 |
Communication link failure |
The communication link between the driver and the data source to which the driver was connected failed before the function completed processing. |
|
22001 |
String data, right truncated |
The FieldIdentifier argument was SQL_DESC_NAME, and the BufferLength argument was a value larger than SQL_MAX_IDENTIFIER_LEN. |
|
HY000 |
General error |
An error occurred for which there was no specific SQLSTATE and for which no implementation-specific SQLSTATE was defined. The error message returned by SQLGetDiagRec in the *MessageText buffer describes the error and its cause. |
|
HY001 |
Memory allocation error |
The driver was unable to allocate memory required to support execution or completion of the function. |
|
HY010 |
Function sequence error |
(DM) The 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. (DM) SQLExecute, SQLExecDirect, SQLBulkOperations, or SQLSetPos was called for the StatementHandle with which the DescriptorHandle was associated and returned SQL_NEED_DATA. This function was called before data was sent for all data-at-execution parameters or columns. (DM) An asynchronously executing function was called for the connection handle that is associated with the DescriptorHandle. This asynchronous function was still executing when the SQLSetDescField function was called. (DM) SQLExecute, SQLExecDirect, or SQLMoreResults was called for one of the statement handles associated with the DescriptorHandle and returned SQL_PARAM_DATA_AVAILABLE. This function was called before data was retrieved for all streamed parameters. |
|
HY013 |
Memory management error |
The function call could not be processed because the underlying memory objects could not be accessed, possibly because of low memory conditions. |
|
HY016 |
Cannot modify an implementation row descriptor |
The DescriptorHandle argument was associated with an IRD, and the FieldIdentifier argument was not SQL_DESC_ARRAY_STATUS_PTR or SQL_DESC_ROWS_PROCESSED_PTR. |
|
HY021 |
Inconsistent descriptor information |
The SQL_DESC_TYPE and SQL_DESC_DATETIME_INTERVAL_CODE fields do not form a valid ODBC SQL type or a valid driver-specific SQL type (for IPDs) or a valid ODBC C type (for APDs or ARDs). Descriptor information checked during a consistency check was not consistent. (See "Consistency Check" in SQLSetDescRec.) |
|
HY090 |
Invalid string or buffer length |
(DM) *ValuePtr is a character string, and BufferLength was less than zero but was not equal to SQL_NTS. (DM) The driver was an ODBC 2.x driver, the descriptor was an ARD, the ColumnNumber argument was set to 0, and the value specified for the argument BufferLength was not equal to 4. |
|
HY091 |
Invalid descriptor field identifier |
The value specified for the FieldIdentifier argument was not an ODBC-defined field and was not an implementation-defined value. The FieldIdentifier argument was invalid for the DescriptorHandle argument. The FieldIdentifier argument was a read-only, ODBC-defined field. |
|
HY092 |
Invalid attribute/option identifier |
The value in *ValuePtr was not valid for the FieldIdentifier argument. The FieldIdentifier argument was SQL_DESC_UNNAMED, and ValuePtr was SQL_NAMED. |
|
HY105 |
Invalid parameter type |
(DM) The value specified for the SQL_DESC_PARAMETER_TYPE field was invalid. (For more information, see the "InputOutputType Argument" section in SQLBindParameter.) |
|
HY117 |
Connection is suspended due to unknown transaction state. Only disconnect and read-only functions are allowed. |
(DM) For more information about suspended state, see What's New in ODBC 3.8. |
|
HYT01 |
Connection timeout expired |
The connection timeout period expired before the data source responded to the request. The connection timeout period is set through SQLSetConnectAttr, SQL_ATTR_CONNECTION_TIMEOUT. |
|
IM001 |
Driver does not support this function |
(DM) The driver associated with the DescriptorHandle does not support the function. |
An application can call SQLSetDescField to set any descriptor field one at a time. One call to SQLSetDescField sets a single field in a single descriptor. This function can be called to set any field in any descriptor type, provided the field can be set. (See the table later in this section.)
Note
|
|---|
|
If a call to SQLSetDescField fails, the contents of the descriptor record identified by the RecNumber argument are undefined. |
Other functions can be called to set multiple descriptor fields with a single call of the function. The SQLSetDescRec function sets a variety of fields that affect the data type and buffer bound to a column or parameter (the SQL_DESC_TYPE, SQL_DESC_DATETIME_INTERVAL_CODE, SQL_DESC_OCTET_LENGTH, SQL_DESC_PRECISION, SQL_DESC_SCALE, SQL_DESC_DATA_PTR, SQL_DESC_OCTET_LENGTH_PTR, and SQL_DESC_INDICATOR_PTR fields). SQLBindCol or SQLBindParameter can be used to make a complete specification for the binding of a column or parameter. These functions set a specific group of descriptor fields with one function call.
SQLSetDescField can be called to change the binding buffers by adding an offset to the binding pointers (SQL_DESC_DATA_PTR, SQL_DESC_INDICATOR_PTR, or SQL_DESC_OCTET_LENGTH_PTR). This changes the binding buffers without calling SQLBindCol or SQLBindParameter, which allows an application to change SQL_DESC_DATA_PTR without changing other fields, such as SQL_DESC_DATA_TYPE.
If an application calls SQLSetDescField to set any field other than SQL_DESC_COUNT or the deferred fields SQL_DESC_DATA_PTR, SQL_DESC_OCTET_LENGTH_PTR, or SQL_DESC_INDICATOR_PTR, the record becomes unbound.
Descriptor header fields are set by calling SQLSetDescField with the appropriate FieldIdentifier. Many header fields are also statement attributes, so they can also be set by a call to SQLSetStmtAttr. This allows applications to set a descriptor field without first obtaining a descriptor handle. When SQLSetDescField is called to set a header field, the RecNumber argument is ignored.
A RecNumber of 0 is used to set bookmark fields.
Note
|
|---|
|
The statement attribute SQL_ATTR_USE_BOOKMARKS should always be set before calling SQLSetDescField to set bookmark fields. While this is not mandatory, it is strongly recommended. |
When setting descriptor fields by calling SQLSetDescField, the application must follow a specific sequence:
-
The application must first set the SQL_DESC_TYPE, SQL_DESC_CONCISE_TYPE, or SQL_DESC_DATETIME_INTERVAL_CODE field.
-
After one of these fields has been set, the application can set an attribute of a data type, and the driver sets data type attribute fields to the appropriate default values for the data type. Automatic defaulting of type attribute fields ensures that the descriptor is always ready to use once the application has specified a data type. If the application explicitly sets a data type attribute, it is overriding the default attribute.
-
After one of the fields listed in step 1 has been set, and data type attributes have been set, the application can set SQL_DESC_DATA_PTR. This prompts a consistency check of descriptor fields. If the application changes the data type or attributes after setting the SQL_DESC_DATA_PTR field, the driver sets SQL_DESC_DATA_PTR to a null pointer, unbinding the record. This forces the application to complete the proper steps in sequence, before the descriptor record is usable.
When a descriptor is allocated, the fields in the descriptor can be initialized to a default value, be initialized without a default value, or be undefined for the type of descriptor. The following tables indicate the initialization of each field for each type of descriptor, with "D" indicating that the field is initialized with a default, and "ND" indicating that the field is initialized without a default. If a number is shown, the default value of the field is that number. The tables also indicate whether a field is read/write (R/W) or read-only (R).
The fields of an IRD have a default value only after the statement has been prepared or executed and the IRD has been populated, not when the statement handle or descriptor has been allocated. Until the IRD has been populated, any attempt to gain access to a field of an IRD will return an error.
Some descriptor fields are defined for one or more, but not all, of the descriptor types (ARDs and IRDs, and APDs and IPDs). When a field is undefined for a type of descriptor, it is not needed by any of the functions that use that descriptor.
The fields that can be accessed by SQLGetDescField cannot necessarily be set by SQLSetDescField. Fields that can be set by SQLSetDescField are listed in the following tables.
The initialization of header fields is outlined in the table that follows.
|
Header field name |
Type |
R/W |
Default |
|---|---|---|---|
|
SQL_DESC_ALLOC_TYPE |
SQLSMALLINT |
ARD: R APD: R IRD: R IPD: R |
ARD: SQL_DESC_ALLOC_AUTO for implicit or SQL_DESC_ALLOC_USER for explicit APD: SQL_DESC_ALLOC_AUTO for implicit or SQL_DESC_ALLOC_USER for explicit IRD: SQL_DESC_ALLOC_AUTO IPD: SQL_DESC_ALLOC_AUTO |
|
SQL_DESC_ARRAY_SIZE |
SQLULEN |
ARD: R/W APD: R/W IRD: Unused IPD: Unused |
ARD:[1] APD:[1] IRD: Unused IPD: Unused |
|
SQL_DESC_ARRAY_STATUS_PTR |
SQLUSMALLINT* |
ARD: R/W APD: R/W IRD: R/W IPD: R/W |
ARD: Null ptr APD: Null ptr IRD: Null ptr IPD: Null ptr |
|
SQL_DESC_BIND_OFFSET_PTR |
SQLLEN* |
ARD: R/W APD: R/W IRD: Unused IPD: Unused |
ARD: Null ptr APD: Null ptr IRD: Unused IPD: Unused |
|
SQL_DESC_BIND_TYPE |
SQLINTEGER |
ARD: R/W APD: R/W IRD: Unused IPD: Unused |
ARD: SQL_BIND_BY_COLUMN APD: SQL_BIND_BY_COLUMN IRD: Unused IPD: Unused |
|
SQL_DESC_COUNT |
SQLSMALLINT |
ARD: R/W APD: R/W IRD: R IPD: R/W |
ARD: 0 APD: 0 IRD: D IPD: 0 |
|
SQL_DESC_ROWS_PROCESSED_PTR |
SQLULEN* |
ARD: Unused APD: Unused IRD: R/W IPD: R/W |
ARD: Unused APD: Unused IRD: Null ptr IPD: Null ptr |
[1] These fields are defined only when the IPD is automatically populated by the driver. If not, they are undefined. If an application attempts to set these fields, SQLSTATE HY091 (Invalid descriptor field identifier) will be returned.
The initialization of record fields is as shown in the following table.
|
Record field name |
Type |
R/W |
Default |
|---|---|---|---|
|
SQL_DESC_AUTO_UNIQUE_VALUE |
SQLINTEGER |
ARD: Unused APD: Unused IRD: R IPD: Unused |
ARD: Unused APD: Unused IRD: D IPD: Unused |
|
SQL_DESC_BASE_COLUMN_NAME |
SQLCHAR * |
ARD: Unused APD: Unused IRD: R IPD: Unused |
ARD: Unused APD: Unused IRD: D IPD: Unused |
|
SQL_DESC_BASE_TABLE_NAME |
SQLCHAR * |
ARD: Unused APD: Unused IRD: R IPD: Unused |
ARD: Unused APD: Unused IRD: D IPD: Unused |
|
SQL_DESC_CASE_SENSITIVE |
SQLINTEGER |
ARD: Unused APD: Unused IRD: R IPD: R |
ARD: Unused APD: Unused IRD: D IPD: D[1] |
|
SQL_DESC_CATALOG_NAME |
SQLCHAR * |
ARD: Unused APD: Unused IRD: R IPD: Unused |
ARD: Unused APD: Unused IRD: D IPD: Unused |
|
SQL_DESC_CONCISE_TYPE |
SQLSMALLINT |
ARD: R/W APD: R/W IRD: R IPD: R/W |
ARD: SQL_C_ DEFAULT APD: SQL_C_ DEFAULT IRD: D IPD: ND |
|
SQL_DESC_DATA_PTR |
SQLPOINTER |
ARD: R/W APD: R/W IRD: Unused IPD: Unused |
ARD: Null ptr APD: Null ptr IRD: Unused IPD: Unused[2] |
|
SQL_DESC_DATETIME_INTERVAL_CODE |
SQLSMALLINT |
ARD: R/W APD: R/W IRD: R IPD: R/W |
ARD: ND APD: ND IRD: D IPD: ND |
|
SQL_DESC_DATETIME_INTERVAL_PRECISION |
SQLINTEGER |
ARD: R/W APD: R/W IRD: R IPD: R/W |
ARD: ND APD: ND IRD: D IPD: ND |
|
SQL_DESC_DISPLAY_SIZE |
SQLLEN |
ARD: Unused APD: Unused IRD: R IPD: Unused |
ARD: Unused APD: Unused IRD: D IPD: Unused |
|
SQL_DESC_FIXED_PREC_SCALE |
SQLSMALLINT |
ARD: Unused APD: Unused IRD: R IPD: R |
ARD: Unused APD: Unused IRD: D IPD: D[1] |
|
SQL_DESC_INDICATOR_PTR |
SQLLEN * |
ARD: R/W APD: R/W IRD: Unused IPD: Unused |
ARD: Null ptr APD: Null ptr IRD: Unused IPD: Unused |
|
SQL_DESC_LABEL |
SQLCHAR * |
ARD: Unused APD: Unused IRD: R IPD: Unused |
ARD: Unused APD: Unused IRD: D IPD: Unused |
|
SQL_DESC_LENGTH |
SQLULEN |
ARD: R/W APD: R/W IRD: R IPD: R/W |
ARD: ND APD: ND IRD: D IPD: ND |
|
SQL_DESC_LITERAL_PREFIX |
SQLCHAR * |
ARD: Unused APD: Unused IRD: R IPD: Unused |
ARD: Unused APD: Unused IRD: D IPD: Unused |
|
SQL_DESC_LITERAL_SUFFIX |
SQLCHAR * |
ARD: Unused APD: Unused IRD: R IPD: Unused |
ARD: Unused APD: Unused IRD: D IPD: Unused |
|
SQL_DESC_LOCAL_TYPE_NAME |
SQLCHAR * |
ARD: Unused APD: Unused IRD: R IPD: R |
ARD: Unused APD: Unused IRD: D IPD: D[1] |
|
SQL_DESC_NAME |
SQLCHAR * |
ARD: Unused APD: Unused IRD: R IPD: R/W |
ARD: ND APD: ND IRD: D IPD: ND |
|
SQL_DESC_NULLABLE |
SQLSMALLINT |
ARD: Unused APD: Unused IRD: R IPD: R |
ARD: ND APD: ND IRD: D IPD: ND |
|
SQL_DESC_NUM_PREC_RADIX |
SQLINTEGER |
ARD: R/W APD: R/W IRD: R IPD: R/W |
ARD: ND APD: ND IRD: D IPD: ND |
|
SQL_DESC_OCTET_LENGTH |
SQLLEN |
ARD: R/W APD: R/W IRD: R IPD: R/W |
ARD: ND APD: ND IRD: D IPD: ND |
|
SQL_DESC_OCTET_LENGTH_PTR |
SQLLEN * |
ARD: R/W APD: R/W IRD: Unused IPD: Unused |
ARD: Null ptr APD: Null ptr IRD: Unused IPD: Unused |
|
SQL_DESC_PARAMETER_TYPE |
SQLSMALLINT |
ARD: Unused APD: Unused IRD: Unused IPD: R/W |
ARD: Unused APD: Unused IRD: Unused IPD: D=SQL_PARAM_INPUT |
|
SQL_DESC_PRECISION |
SQLSMALLINT |
ARD: R/W APD: R/W IRD: R IPD: R/W |
ARD: ND APD: ND IRD: D IPD: ND |
|
SQL_DESC_ROWVER |
SQLSMALLINT |
ARD: Unused APD: Unused IRD: R IPD: R |
ARD: Unused APD: Unused IRD: ND IPD: ND |
|
SQL_DESC_SCALE |
SQLSMALLINT |
ARD: R/W APD: R/W IRD: R IPD: R/W |
ARD: ND APD: ND IRD: D IPD: ND |
|
SQL_DESC_SCHEMA_NAME |
SQLCHAR * |
ARD: Unused APD: Unused IRD: R IPD: Unused |
ARD: Unused APD: Unused IRD: D IPD: Unused |
|
SQL_DESC_SEARCHABLE |
SQLSMALLINT |
ARD: Unused APD: Unused IRD: R IPD: Unused |
ARD: Unused APD: Unused IRD: D IPD: Unused |
|
SQL_DESC_TABLE_NAME |
SQLCHAR * |
ARD: Unused APD: Unused IRD: R IPD: Unused |
ARD: Unused APD: Unused IRD: D IPD: Unused |
|
SQL_DESC_TYPE |
SQLSMALLINT |
ARD: R/W APD: R/W IRD: R IPD: R/W |
ARD: SQL_C_DEFAULT APD: SQL_C_DEFAULT IRD: D IPD: ND |
|
SQL_DESC_TYPE_NAME |
SQLCHAR * |
ARD: Unused APD: Unused IRD: R IPD: R |
ARD: Unused APD: Unused IRD: D IPD: D[1] |
|
SQL_DESC_UNNAMED |
SQLSMALLINT |
ARD: Unused APD: Unused IRD: R IPD: R/W |
ARD: ND APD: ND IRD: D IPD: ND |
|
SQL_DESC_UNSIGNED |
SQLSMALLINT |
ARD: Unused APD: Unused IRD: R IPD: R |
ARD: Unused APD: Unused IRD: D IPD: D[1] |
|
SQL_DESC_UPDATABLE |
SQLSMALLINT |
ARD: Unused APD: Unused IRD: R IPD: Unused |
ARD: Unused APD: Unused IRD: D IPD: Unused |
[1] These fields are defined only when the IPD is automatically populated by the driver. If not, they are undefined. If an application attempts to set these fields, SQLSTATE HY091 (Invalid descriptor field identifier) will be returned.
[2] The SQL_DESC_DATA_PTR field in the IPD can be set to force a consistency check. In a subsequent call to SQLGetDescField or SQLGetDescRec, the driver is not required to return the value that SQL_DESC_DATA_PTR was set to.
The FieldIdentifier argument indicates the descriptor field to be set. A descriptor contains the descriptor header, consisting of the header fields described in the next section, "Header Fields," and zero or more descriptor records, consisting of the record fields described in the section following the "Header Fields" section.
A consistency check is performed by the driver automatically whenever an application passes in a value for the SQL_DESC_DATA_PTR field of the ARD, APD, or IPD. If any of the fields is inconsistent with other fields, SQLSetDescField will return SQLSTATE HY021 (Inconsistent descriptor information). For more information, see "Consistency Check" in SQLSetDescRec.
Note