SQLSetStmtAttr Function

Conformance
Version Introduced: ODBC 3.0 Standards Compliance: ISO 92

Summary
SQLSetStmtAttr sets attributes related to a statement.

Note

For more information about what the Driver Manager maps this function to when an ODBC 3.x application is working with an ODBC 2.x driver, see Mapping Replacement Functions for Backward Compatibility of Applications.

Syntax

  
SQLRETURN SQLSetStmtAttr(  
     SQLHSTMT      StatementHandle,  
     SQLINTEGER    Attribute,  
     SQLPOINTER    ValuePtr,  
     SQLINTEGER    StringLength);  

Arguments

StatementHandle
[Input] Statement handle.

Attribute
[Input] Option to set, listed in "Comments."

ValuePtr
[Input] Value to be associated with Attribute. Depending on the value of Attribute, ValuePtr will be one of the following:

  • An ODBC descriptor handle.

  • A SQLUINTEGER value.

  • A SQLULEN value.

  • A pointer to one of the following:

    • A null-terminated character string.

    • A binary buffer.

    • A value or array of type SQLLEN, SQLULEN, or SQLUSMALLINT.

    • A driver-defined value.

If the Attribute argument is a driver-specific value, ValuePtr may be a signed integer.

StringLength
[Input] If Attribute is an ODBC-defined attribute and ValuePtr points to a character string or a binary buffer, this argument should be the length of *ValuePtr. If Attribute is an ODBC-defined attribute and ValuePtr is an integer, StringLength is ignored.

If Attribute is a driver-defined attribute, the application indicates the nature of the attribute to the Driver Manager by setting the StringLength argument. StringLength can have the following values:

  • If ValuePtr is a pointer to a character string, then StringLength is the length of the string or SQL_NTS.

  • If ValuePtr is a pointer to a binary buffer, then the application places the result of the SQL_LEN_BINARY_ATTR(length) macro in StringLength. This places a negative value in StringLength.

  • If ValuePtr is a pointer to a value other than a character string or a binary string, then StringLength should have the value SQL_IS_POINTER.

  • If ValuePtr contains a fixed-length value, then StringLength is either SQL_IS_INTEGER or SQL_IS_UINTEGER, as appropriate.

Returns

SQL_SUCCESS, SQL_SUCCESS_WITH_INFO, SQL_ERROR, or SQL_INVALID_HANDLE.

Diagnostics

When SQLSetStmtAttr returns SQL_ERROR or SQL_SUCCESS_WITH_INFO, an associated SQLSTATE value may be obtained by calling SQLGetDiagRec with a HandleType of SQL_HANDLE_STMT and a Handle of StatementHandle. The following table lists the SQLSTATE values commonly returned by SQLSetStmtAttr 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, or the value specified in ValuePtr was invalid because of implementation working conditions, so the driver substituted a similar value. (SQLGetStmtAttr can be called to determine the temporarily substituted value.) The substitute value is valid for the StatementHandle until the cursor is closed, at which point the statement attribute reverts to its previous value. The statement attributes that can be changed are:

SQL_ ATTR_CONCURRENCY SQL_ ATTR_CURSOR_TYPE SQL_ ATTR_KEYSET_SIZE SQL_ ATTR_MAX_LENGTH SQL_ ATTR_MAX_ROWS SQL_ ATTR_QUERY_TIMEOUT SQL_ATTR_ROW_ARRAY_SIZE SQL_ ATTR_SIMULATE_CURSOR

(Function returns SQL_SUCCESS_WITH_INFO.)
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.
24000 Invalid cursor state The Attribute was SQL_ATTR_CONCURRENCY, SQL_ATTR_CURSOR_TYPE, SQL_ATTR_SIMULATE_CURSOR, or SQL_ATTR_USE_BOOKMARKS, and the cursor was open.
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.
HY009 Invalid use of null pointer The Attribute argument identified a statement attribute that required a string attribute, and the ValuePtr argument was a null pointer.
HY010 Function sequence error (DM) An asynchronously executing function was called for the connection handle that is associated with the StatementHandle. This asynchronous function was still executing when the SQLSetStmtAttr function was called.

(DM) SQLExecute, SQLExecDirect, or SQLMoreResults was called for the StatementHandle and returned SQL_PARAM_DATA_AVAILABLE. This function was called before data was retrieved for all streamed parameters.

(DM) An asynchronously executing function was called for the StatementHandle and was still executing when this function was called.

(DM) SQLExecute, SQLExecDirect, SQLBulkOperations, or SQLSetPos was called for the StatementHandle and returned SQL_NEED_DATA. This function was called before data was sent for all data-at-execution parameters or columns.
HY011 Attribute cannot be set now The Attribute was SQL_ATTR_CONCURRENCY, SQL_ ATTR_CURSOR_TYPE, SQL_ ATTR_SIMULATE_CURSOR, or SQL_ ATTR_USE_BOOKMARKS, and the statement was prepared.
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.
HY017 Invalid use of an automatically allocated descriptor handle (DM) The Attribute argument was SQL_ATTR_IMP_ROW_DESC or SQL_ATTR_IMP_PARAM_DESC.

(DM) The Attribute argument was SQL_ATTR_APP_ROW_DESC or SQL_ATTR_APP_PARAM_DESC, and the value in ValuePtr was an implicitly allocated descriptor handle other than the handle originally allocated for the ARD or APD.
HY024 Invalid attribute value Given the specified Attribute value, an invalid value was specified in ValuePtr. (The Driver Manager returns this SQLSTATE only for connection and statement attributes that accept a discrete set of values, such as SQL_ATTR_ACCESS_MODE or SQL_ ATTR_ASYNC_ENABLE. For all other connection and statement attributes, the driver must verify the value specified in ValuePtr.)

The Attribute argument was SQL_ATTR_APP_ROW_DESC or SQL_ATTR_APP_PARAM_DESC, and ValuePtr was an explicitly allocated descriptor handle that is not on the same connection as the StatementHandle argument.
HY090 Invalid string or buffer length (DM) *ValuePtr is a character string, and the StringLength argument was less than 0 but was not SQL_NTS.
HY092 Invalid attribute/option identifier (DM) The value specified for the argument Attribute was not valid for the version of ODBC supported by the driver.

(DM) The value specified for the argument Attribute was a read-only attribute.
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 SQLEndTran Function.
HYC00 Optional feature not implemented The value specified for the argument Attribute was a valid ODBC statement attribute for the version of ODBC supported by the driver but was not supported by the driver.

The Attribute argument was SQL_ATTR_ASYNC_ENABLE, and a call to SQLGetInfo with an InfoType of SQL_ASYNC_MODE returns SQL_AM_CONNECTION.

The Attribute argument was SQL_ATTR_ENABLE_AUTO_IPD, and the value of the connection attribute SQL_ATTR_AUTO_IPD was SQL_FALSE.
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 StatementHandle does not support the function.
S1118 Driver does not support asynchronous notification If calling SQLSetStmtAttr to set SQL_ATTR_ASYNC_STMT_EVENT; asynchronous notification is not supported by the driver.

Comments

Statement attributes for a statement remain in effect until they are changed by another call to SQLSetStmtAttr or until the statement is dropped by calling SQLFreeHandle. Calling SQLFreeStmt with the SQL_CLOSE, SQL_UNBIND, or SQL_RESET_PARAMS option does not reset statement attributes.

Some statement attributes support substitution of a similar value if the data source does not support the value specified in ValuePtr. In such cases, the driver returns SQL_SUCCESS_WITH_INFO and SQLSTATE 01S02 (Option value changed). For example, if Attribute is SQL_ATTR_CONCURRENCY and ValuePtr is SQL_CONCUR_ROWVER, and if the data source does not support this, the driver substitutes SQL_CONCUR_VALUES and returns SQL_SUCCESS_WITH_INFO. To determine the substituted value, an application calls SQLGetStmtAttr.

The format of information set with ValuePtr depends on the specified Attribute. SQLSetStmtAttr accepts attribute information in one of two different formats: a character string or an integer value. The format of each is noted in the attribute's description. This format applies to the information returned for each attribute in SQLGetStmtAttr. Character strings pointed to by the ValuePtr argument of SQLSetStmtAttr have a length of StringLength.

Note

The ability to set statement attributes at the connection level by calling SQLSetConnectAttr has been deprecated in ODBC 3.x. ODBC 3.x applications should never set statement attributes at the connection level. ODBC 3.x statement attributes cannot be set at the connection level, with the exception of the SQL_ATTR_METADATA_ID and SQL_ATTR_ASYNC_ENABLE attributes, which are both connection attributes and statement attributes, and can be set at either the connection level or the statement level.

Note

ODBC 3.x drivers need only support this functionality if they should work with ODBC 2.x applications that set ODBC 2.x statement options at the connection level. For more information, see "Setting Statement Options on the Connection Level" under SQLSetConnectOption Mapping in Appendix G: Driver Guidelines for Backward Compatibility.

Statement Attributes That Set Descriptor Fields

Many statement attributes correspond to a header field of a descriptor. Setting these attributes actually results in the setting of the descriptor fields. Setting fields by a call to SQLSetStmtAttr rather than to SQLSetDescField has the advantage that a descriptor handle does not have to be obtained for the function call.

Caution

Calling SQLSetStmtAttr for one statement can affect other statements. This occurs when the APD or ARD associated with the statement is explicitly allocated and is also associated with other statements. Because SQLSetStmtAttr modifies the APD or ARD, the modifications apply to all statements with which this descriptor is associated. If this is not the required behavior, the application should dissociate this descriptor from the other statements (by calling SQLSetStmtAttr to set the SQL_ATTR_APP_ROW_DESC or SQL_ATTR_APP_PARAM_DESC field to a different descriptor handle) before calling SQLSetStmtAttr again.

When a descriptor field is set as a result of the corresponding statement attribute being set, the field is set only for the applicable descriptors that are currently associated with the statement identified by the StatementHandle argument, and the attribute setting does not affect any descriptors that may be associated with that statement in the future. When a descriptor field that is also a statement attribute is set by a call to SQLSetDescField, the corresponding statement attribute is set. If an explicitly allocated descriptor is dissociated from a statement, a statement attribute that corresponds to a header field will revert to the value of the field in the implicitly allocated descriptor.

When a statement is allocated (see SQLAllocHandle), four descriptor handles are automatically allocated and associated with the statement. Explicitly allocated descriptor handles can be associated with the statement by calling SQLAllocHandle with an fHandleType of SQL_HANDLE_DESC to allocate a descriptor handle and then calling SQLSetStmtAttr to associate the descriptor handle with the statement.

The statement attributes in the following table correspond to descriptor header fields.

Statement attribute Header field Desc.
SQL_ATTR_PARAM_BIND_OFFSET_PTR SQL_DESC_BIND_OFFSET_PTR APD
SQL_ATTR_PARAM_BIND_TYPE SQL_DESC_BIND_TYPE APD
SQL_ATTR_PARAM_OPERATION_PTR SQL_DESC_ARRAY_STATUS_PTR APD
SQL_ATTR_PARAM_STATUS_PTR SQL_DESC_ARRAY_STATUS_PTR IPD
SQL_ATTR_PARAMS_PROCESSED_PTR SQL_DESC_ROWS_PROCESSED_PTR IPD
SQL_ATTR_PARAMSET_SIZE SQL_DESC_ARRAY_SIZE APD
SQL_ATTR_ROW_ARRAY_SIZE SQL_DESC_ARRAY_SIZE ARD
SQL_ATTR_ROW_BIND_OFFSET_PTR SQL_DESC_BIND_OFFSET_PTR ARD
SQL_ATTR_ROW_BIND_TYPE SQL_DESC_BIND_TYPE ARD
SQL_ATTR_ROW_OPERATION_PTR SQL_DESC_ARRAY_STATUS_PTR ARD
SQL_ATTR_ROW_STATUS_PTR SQL_DESC_ARRAY_STATUS_PTR IRD
SQL_ATTR_ROWS_FETCHED_PTR SQL_DESC_ROWS_PROCESSED_PTR IRD

Statement Attributes

The currently defined attributes and the version of ODBC in which they were introduced are shown in the following table; it is expected that more attributes will be defined by drivers to take advantage of different data sources. A range of attributes is reserved by ODBC; driver developers must reserve values for their own driver-specific use from Open Group. For more information, see Driver-Specific Data Types, Descriptor Types, Information Types, Diagnostic Types, and Attributes.

Attribute ValuePtr contents
SQL_ATTR_APP_PARAM_DESC (ODBC 3.0) The handle to the APD for subsequent calls to SQLExecute and SQLExecDirect on the statement handle. The initial value of this attribute is the descriptor implicitly allocated when the statement was initially allocated. If the value of this attribute is set to SQL_NULL_DESC or the handle originally allocated for the descriptor, an explicitly allocated APD handle that was previously associated with the statement handle is dissociated from it and the statement handle reverts to the implicitly allocated APD handle.

This attribute cannot be set to a descriptor handle that was implicitly allocated for another statement or to another descriptor handle that was implicitly set on the same statement; implicitly allocated descriptor handles cannot be associated with more than one statement or descriptor handle.
SQL_ATTR_APP_ROW_DESC (ODBC 3.0) The handle to the ARD for subsequent fetches on the statement handle. The initial value of this attribute is the descriptor implicitly allocated when the statement was initially allocated. If the value of this attribute is set to SQL_NULL_DESC or the handle originally allocated for the descriptor, an explicitly allocated ARD handle that was previously associated with the statement handle is dissociated from it and the statement handle reverts to the implicitly allocated ARD handle.

This attribute cannot be set to a descriptor handle that was implicitly allocated for another statement or to another descriptor handle that was implicitly set on the same statement; implicitly allocated descriptor handles cannot be associated with more than one statement or descriptor handle.
SQL_ATTR_ASYNC_ENABLE (ODBC 1.0) A SQLULEN value that specifies whether a function called with the specified statement is executed asynchronously:

SQL_ASYNC_ENABLE_OFF = Disable statement level asynchronous execution support (the default).

SQL_ASYNC_ENABLE_ON = Enable statement level asynchronous execution support.

For more information, see Asynchronous Execution (Polling Method).

For drivers with statement level asynchronous execution support, the statement attribute SQL_ATTR_ASYNC_ENABLE is read only. Its value is the same as the value of the connection level attribute with the same name at the time the statement handle was allocated.

Calling SQLSetStmtAttr to set SQL_ATTR_ASYNC_ENABLE when the SQL_ASYNC_MODE InfoType returns SQL_AM_CONNECTION returns SQLSTATE HYC00 (Optional feature not implemented). For more information, see SQLSetConnectAttr Function for more information.
SQL_ATTR_ASYNC_STMT_EVENT (ODBC 3.8) A SQLPOINTER value that is an event handle.

Notification of completion of asynchronous functions is enabled by calling SQLSetStmtAttr to set the SQL_ATTR_ASYNC_STMT_EVENT attribute and specify the event handle.
SQL_ATTR_ASYNC_STMT_PCALLBACK (ODBC 3.8) A SQLPOINTER to the asynchronous callback function.

Only the Driver Manager can call a driver's SQLSetStmtAttr function with this attribute.
SQL_ATTR_ASYNC_STMT_PCONTEXT (ODBC 3.8) A SQLPOINTER to the context structure

Only the Driver Manager can call a driver's SQLSetStmtAttr function with this attribute.
SQL_ATTR_CONCURRENCY (ODBC 2.0) An SQLULEN value that specifies the cursor concurrency:

SQL_CONCUR_READ_ONLY = Cursor is read-only. No updates are allowed.

SQL_CONCUR_LOCK = Cursor uses the lowest level of locking sufficient to ensure that the row can be updated.

SQL_CONCUR_ROWVER = Cursor uses optimistic concurrency control, comparing row versions such as SQLBase ROWID or Sybase TIMESTAMP.

SQL_CONCUR_VALUES = Cursor uses optimistic concurrency control, comparing values.

The default value for SQL_ATTR_CONCURRENCY is SQL_CONCUR_READ_ONLY.

This attribute cannot be specified for an open cursor. For more information, see Concurrency Types.

If the SQL_ATTR_CURSOR_TYPE Attribute is changed to a type that does not support the current value of SQL_ATTR_CONCURRENCY, the value of SQL_ATTR_CONCURRENCY will be changed at execution time, and a warning issued when SQLExecDirect or SQLPrepare is called.

If the driver supports the SELECT FOR UPDATE statement and such a statement is executed while the value of SQL_ATTR_CONCURRENCY is set to SQL_CONCUR_READ_ONLY, an error will be returned. If the value of SQL_ATTR_CONCURRENCY is changed to a value that the driver supports for some value of SQL_ATTR_CURSOR_TYPE but not for the current value of SQL_ATTR_CURSOR_TYPE, the value of SQL_ATTR_CURSOR_TYPE will be changed at execution time and SQLSTATE 01S02 (Option value changed) is issued when SQLExecDirect or SQLPrepare is called.

If the specified concurrency is not supported by the data source, the driver substitutes a different concurrency and returns SQLSTATE 01S02 (Option value changed). For SQL_CONCUR_VALUES, the driver substitutes SQL_CONCUR_ROWVER, and vice versa. For SQL_CONCUR_LOCK, the driver substitutes, in order, SQL_CONCUR_ROWVER or SQL_CONCUR_VALUES. The validity of the substituted value is not checked until execution time.

For more information about the relationship between SQL_ATTR_CONCURRENCY and the other cursor attributes, see Cursor Characteristics and Cursor Type.
SQL_ATTR_CURSOR_SCROLLABLE (ODBC 3.0) An SQLULEN value that specifies the level of support that the application requires. Setting this attribute affects subsequent calls to SQLExecDirect and SQLExecute.

SQL_NONSCROLLABLE = Scrollable cursors are not required on the statement handle. If the application calls SQLFetchScroll on this handle, the only valid value of FetchOrientation is SQL_FETCH_NEXT. This is the default.

SQL_SCROLLABLE = Scrollable cursors are required on the statement handle. When calling SQLFetchScroll, the application may specify any valid value of FetchOrientation, achieving cursor positioning in modes other than the sequential mode.

For more information about scrollable cursors, see Scrollable Cursors. For more information about the relationship between SQL_ATTR_CURSOR_SCROLLABLE and the other cursor attributes, see Cursor Characteristics and Cursor Type
SQL_ATTR_CURSOR_SENSITIVITY (ODBC 3.0) An SQLULEN value that specifies whether cursors on the statement handle make visible the changes made to a result set by another cursor. Setting this attribute affects subsequent calls to SQLExecDirect and SQLExecute. An application can read back the value of this attribute to obtain its initial state or its state as most recently set by the application.

SQL_UNSPECIFIED = It is unspecified what the cursor type is and whether cursors on the statement handle make visible the changes made to a result set by another cursor. Cursors on the statement handle may make visible none, some, or all such changes. This is the default.

SQL_INSENSITIVE = All cursors on the statement handle show the result set without reflecting any changes made to it by any other cursor. Insensitive cursors are read-only. This corresponds to a static cursor, which has a concurrency that is read-only.

SQL_SENSITIVE = All cursors on the statement handle make visible all changes made to a result set by another cursor.

For more information about the relationship between SQL_ATTR_CURSOR_SENSITIVITY and the other cursor attributes, see Cursor Characteristics and Cursor Type.
SQL_ATTR_CURSOR_TYPE (ODBC 2.0) An SQLULEN value that specifies the cursor type:

SQL_CURSOR_FORWARD_ONLY = The cursor only scrolls forward.

SQL_CURSOR_STATIC = The data in the result set is static.

SQL_CURSOR_KEYSET_DRIVEN = The driver saves and uses the keys for the number of rows specified in the SQL_ATTR_KEYSET_SIZE statement attribute.

SQL_CURSOR_DYNAMIC = The driver saves and uses only the keys for the rows in the rowset.

The default value is SQL_CURSOR_FORWARD_ONLY. This attribute cannot be specified after the SQL statement has been prepared.

If the specified cursor type is not supported by the data source, the driver substitutes a different cursor type and returns SQLSTATE 01S02 (Option value changed). For a mixed or dynamic cursor, the driver substitutes, in order, a keyset-driven or static cursor. For a keyset-driven cursor, the driver substitutes a static cursor.

For more information about scrollable cursor types, see Scrollable Cursor Types. For more information about the relationship between SQL_ATTR_CURSOR_TYPE and the other cursor attributes, see Cursor Characteristics and Cursor Type.
SQL_ATTR_ENABLE_AUTO_IPD (ODBC 3.0) An SQLULEN value that specifies whether automatic population of the IPD is performed:

SQL_TRUE = Turns on automatic population of the IPD after a call to SQLPrepare. SQL_FALSE = Turns off automatic population of the IPD after a call to SQLPrepare. (An application can still obtain IPD field information by calling SQLDescribeParam, if supported.) The default value of the statement attribute SQL_ATTR_ENABLE_AUTO_IPD is SQL_FALSE. For more information, see Automatic Population of the IPD.
SQL_ATTR_FETCH_BOOKMARK_PTR (ODBC 3.0) A SQLLEN * that points to a binary bookmark value. When SQLFetchScroll is called with fFetchOrientation equal to SQL_FETCH_BOOKMARK, the driver picks up the bookmark value from this field. This field defaults to a null pointer. For more information, see Scrolling by Bookmark.

The value pointed to by this field is not used for delete by bookmark, update by bookmark, or fetch by bookmark operations in SQLBulkOperations, which use bookmarks cached in rowset buffers.
SQL_ATTR_IMP_PARAM_DESC (ODBC 3.0) The handle to the IPD. The value of this attribute is the descriptor allocated when the statement was initially allocated. The application cannot set this attribute.

This attribute can be retrieved by a call to SQLGetStmtAttr but not set by a call to SQLSetStmtAttr.
SQL_ATTR_IMP_ROW_DESC (ODBC 3.0) The handle to the IRD. The value of this attribute is the descriptor allocated when the statement was initially allocated. The application cannot set this attribute.

This attribute can be retrieved by a call to SQLGetStmtAttr but not set by a call to SQLSetStmtAttr.
SQL_ATTR_KEYSET_SIZE (ODBC 2.0) An SQLULEN that specifies the number of rows in the keyset for a keyset-driven cursor. If the keyset size is 0 (the default), the cursor is fully keyset-driven. If the keyset size is greater than 0, the cursor is mixed (keyset-driven within the keyset and dynamic outside of the keyset). The default keyset size is 0. For more information about keyset-driven cursors, see Keyset-Driven Cursors.

If the specified size exceeds the maximum keyset size, the driver substitutes that size and returns SQLSTATE 01S02 (Option value changed).

SQLFetch or SQLFetchScroll returns an error if the keyset size is greater than 0 and less than the rowset size.
SQL_ATTR_MAX_LENGTH (ODBC 1.0) An SQLULEN value that specifies the maximum amount of data that the driver returns from a character or binary column. If ValuePtr is less than the length of the available data, SQLFetch or SQLGetData truncates the data and returns SQL_SUCCESS. If ValuePtr is 0 (the default), the driver attempts to return all available data.

If the specified length is less than the minimum amount of data that the data source can return or greater than the maximum amount of data that the data source can return, the driver substitutes that value and returns SQLSTATE 01S02 (Option value changed).

The value of this attribute can be set on an open cursor; however, the setting might not take effect immediately, in which case the driver will return SQLSTATE 01S02 (Option value changed) and reset the attribute to its original value.

This attribute is intended to reduce network traffic and should be supported only when the data source (as opposed to the driver) in a multiple-tier driver can implement it. This mechanism should not be used by applications to truncate data; to truncate data received, an application should specify the maximum buffer length in the BufferLength argument in SQLBindCol or SQLGetData.
SQL_ATTR_MAX_ROWS (ODBC 1.0) An SQLULEN value corresponding to the maximum number of rows to return to the application for a SELECT statement. If *ValuePtr equals 0 (the default), the driver returns all rows.

This attribute is intended to reduce network traffic. Conceptually, it is applied when the result set is created and limits the result set to the first ValuePtr rows. If the number of rows in the result set is greater than ValuePtr, the result set is truncated.

SQL_ATTR_MAX_ROWS applies to all result sets on the Statement, including those returned by catalog functions. SQL_ATTR_MAX_ROWS establishes a maximum for the value of the cursor row count.

A driver should not emulate SQL_ATTR_MAX_ROWS behavior for SQLFetch or SQLFetchScroll (if result set size limitations cannot be implemented at the data source) if it cannot guarantee that SQL_ATTR_MAX_ROWS will be implemented properly.

It is driver-defined whether SQL_ATTR_MAX_ROWS applies to statements other than SELECT statements (such as catalog functions).

The value of this attribute can be set on an open cursor; however, the setting might not take effect immediately, in which case the driver will return SQLSTATE 01S02 (Option value changed) and reset the attribute to its original value.
SQL_ATTR_METADATA_ID (ODBC 3.0) An SQLULEN value that determines how the string arguments of catalog functions are treated.

If SQL_TRUE, the string argument of catalog functions are treated as identifiers. The case is not significant. For nondelimited strings, the driver removes any trailing spaces and the string is folded to uppercase. For delimited strings, the driver removes any leading or trailing spaces and takes whatever is between the delimiters literally. If one of these arguments is set to a null pointer, the function returns SQL_ERROR and SQLSTATE HY009 (Invalid use of null pointer).

If SQL_FALSE, the string arguments of catalog functions are not treated as identifiers. The case is significant. They can either contain a string search pattern or not, depending on the argument.

The default value is SQL_FALSE.

The TableType argument of SQLTables, which takes a list of values, is not affected by this attribute.

SQL_ATTR_METADATA_ID can also be set on the connection level. (It and SQL_ATTR_ASYNC_ENABLE are the only statement attributes that are also connection attributes.)

For more information, see Arguments in Catalog Functions.
SQL_ATTR_NOSCAN (ODBC 1.0) An SQLULEN value that indicates whether the driver should scan SQL strings for escape sequences:

SQL_NOSCAN_OFF = The driver scans SQL strings for escape sequences (the default).

SQL_NOSCAN_ON = The driver does not scan SQL strings for escape sequences. Instead, the driver sends the statement directly to the data source.

For more information, see Escape Sequences in ODBC.
SQL_ATTR_PARAM_BIND_OFFSET_PTR (ODBC 3.0) An SQLULEN * value that points to an offset added to pointers to change binding of dynamic parameters. If this field is non-null, the driver dereferences the pointer, adds the dereferenced value to each of the deferred fields in the descriptor record (SQL_DESC_DATA_PTR, SQL_DESC_INDICATOR_PTR, and SQL_DESC_OCTET_LENGTH_PTR), and uses the new pointer values when binding. It is set to null by default.

The bind offset is always added directly to the SQL_DESC_DATA_PTR, SQL_DESC_INDICATOR_PTR, and SQL_DESC_OCTET_LENGTH_PTR fields. If the offset is changed to a different value, the new value is still added directly to the value in the descriptor field. The new offset is not added to the field value plus any earlier offsets.

For more information, see Parameter Binding Offsets.

Setting this statement attribute sets the SQL_DESC_BIND_OFFSET_PTR field in the APD header.
SQL_ATTR_PARAM_BIND_TYPE (ODBC 3.0) An SQLULEN value that indicates the binding orientation to be used for dynamic parameters.

This field is set to SQL_PARAM_BIND_BY_COLUMN (the default) to select column-wise binding.

To select row-wise binding, this field is set to the length of the structure or an instance of a buffer that will be bound to a set of dynamic parameters. This length must include space for all of the bound parameters and any padding of the structure or buffer to ensure that when the address of a bound parameter is incremented with the specified length, the result will point to the beginning of the same parameter in the next set of parameters. When using the sizeof operator in ANSI C, this behavior is guaranteed.

For more information, see Binding Arrays of Parameters.

Setting this statement attribute sets the SQL_DESC_ BIND_TYPE field in the APD header.
SQL_ATTR_PARAM_OPERATION_PTR (ODBC 3.0) An SQLUSMALLINT * value that points to an array of SQLUSMALLINT values used to ignore a parameter during execution of an SQL statement. Each value is set to either SQL_PARAM_PROCEED (for the parameter to be executed) or SQL_PARAM_IGNORE (for the parameter to be ignored).

A set of parameters can be ignored during processing by setting the status value in the array pointed to by SQL_DESC_ARRAY_STATUS_PTR in the APD to SQL_PARAM_IGNORE. A set of parameters is processed if its status value is set to SQL_PARAM_PROCEED or if no elements in the array are set.

This statement attribute can be set to a null pointer, in which case the driver does not return parameter status values. This attribute can be set at any time, but the new value is not used until the next time SQLExecDirect or SQLExecute is called.

This attribute is ignored when there is no bound parameter.

For more information, see Using Arrays of Parameters.

Setting this statement attribute sets the SQL_DESC_ARRAY_STATUS_PTR field in the APD header.
SQL_ATTR_PARAM_STATUS_PTR (ODBC 3.0) An SQLUSMALLINT * value that points to an array of SQLUSMALLINT values containing status information for each row of parameter values after a call to SQLExecute or SQLExecDirect. This field is required only if PARAMSET_SIZE is greater than 1.

The status values can contain the following values:

SQL_PARAM_SUCCESS: The SQL statement was successfully executed for this set of parameters.

SQL_PARAM_SUCCESS_WITH_INFO: The SQL statement was successfully executed for this set of parameters; however, warning information is available in the diagnostics data structure.

SQL_PARAM_ERROR: There was an error in processing this set of parameters. Additional error information is available in the diagnostics data structure.

SQL_PARAM_UNUSED: This parameter set was unused, possibly due to the fact that some previous parameter set caused an error that aborted further processing, or because SQL_PARAM_IGNORE was set for that set of parameters in the array specified by the SQL_ATTR_PARAM_OPERATION_PTR.

SQL_PARAM_DIAG_UNAVAILABLE: The driver treats arrays of parameters as a monolithic unit and so does not generate this level of error information.

This statement attribute can be set to a null pointer, in which case the driver does not return parameter status values. This attribute can be set at any time, but the new value is not used until the next time SQLExecute or SQLExecDirect is called. Note that setting this attribute can affect the output parameter behavior implemented by the driver.

For more information, see Using Arrays of Parameters.

Setting this statement attribute sets the SQL_DESC_ARRAY_STATUS_PTR field in the IPD header.
SQL_ATTR_PARAMS_PROCESSED_PTR (ODBC 3.0) An SQLULEN * record field that points to a buffer in which to return the number of sets of parameters that have been processed, including error sets. No number will be returned if this is a null pointer.

Setting this statement attribute sets the SQL_DESC_ROWS_PROCESSED_PTR field in the IPD header.

If the call to SQLExecDirect or SQLExecute that fills in the buffer pointed to by this attribute does not return SQL_SUCCESS or SQL_SUCCESS_WITH_INFO, the contents of the buffer are undefined.

For more information, see Using Arrays of Parameters.
SQL_ATTR_PARAMSET_SIZE (ODBC 3.0) An SQLULEN value that specifies the number of values for each parameter. If SQL_ATTR_PARAMSET_SIZE is greater than 1, SQL_DESC_DATA_PTR, SQL_DESC_INDICATOR_PTR, and SQL_DESC_OCTET_LENGTH_PTR of the APD point to arrays. The cardinality of each array is equal to the value of this field.

This attribute is ignored when there is no bound parameter.

For more information, see Using Arrays of Parameters.

Setting this statement attribute sets the SQL_DESC_ARRAY_SIZE field in the APD header.
SQL_ATTR_QUERY_TIMEOUT (ODBC 1.0) An SQLULEN value corresponding to the number of seconds to wait for an SQL statement to execute before returning to the application. If ValuePtr is equal to 0 (default), there is no timeout.

If the specified timeout exceeds the maximum timeout in the data source or is smaller than the minimum timeout, SQLSetStmtAttr substitutes that value and returns SQLSTATE 01S02 (Option value changed).

Note that the application need not call SQLCloseCursor to reuse the statement if a SELECT statement timed out.

The query timeout set in this statement attribute is valid in both synchronous and asynchronous modes.
SQL_ATTR_RETRIEVE_DATA (ODBC 2.0) An SQLULEN value:

SQL_RD_ON = SQLFetchScroll and, in ODBC 3.x, SQLFetch retrieve data after it positions the cursor to the specified location. This is the default.

SQL_RD_OFF = SQLFetchScroll and, in ODBC 3.x, SQLFetch do not retrieve data after it positions the cursor.

By setting SQL_RETRIEVE_DATA to SQL_RD_OFF, an application can verify that a row exists or retrieve a bookmark for the row without incurring the overhead of retrieving rows. For more information, see Scrolling and Fetching Rows.

The value of this attribute can be set on an open cursor; however, the setting might not take effect immediately, in which case the driver will return SQLSTATE 01S02 (Option value changed) and reset the attribute to its original value.
SQL_ATTR_ROW_ARRAY_SIZE (ODBC 3.0) An SQLULEN value that specifies the number of rows returned by each call to SQLFetch or SQLFetchScroll. It is also the number of rows in a bookmark array used in a bulk bookmark operation in SQLBulkOperations. The default value is 1.

If the specified rowset size exceeds the maximum rowset size supported by the data source, the driver substitutes that value and returns SQLSTATE 01S02 (Option value changed).

For more information, see Rowset Size.

Setting this statement attribute sets the SQL_DESC_ARRAY_SIZE field in the ARD header.
SQL_ATTR_ROW_BIND_OFFSET_PTR (ODBC 3.0) An SQLULEN * value that points to an offset added to pointers to change binding of column data. If this field is non-null, the driver dereferences the pointer, adds the dereferenced value to each of the deferred fields in the descriptor record (SQL_DESC_DATA_PTR, SQL_DESC_INDICATOR_PTR, and SQL_DESC_OCTET_LENGTH_PTR), and uses the new pointer values when binding. It is set to null by default.

Setting this statement attribute sets the SQL_DESC_BIND_OFFSET_PTR field in the ARD header.
SQL_ATTR_ROW_BIND_TYPE (ODBC 1.0) An SQLULEN value that sets the binding orientation to be used when SQLFetch or SQLFetchScroll is called on the associated statement. Column-wise binding is selected by setting the value to SQL_BIND_BY_COLUMN. Row-wise binding is selected by setting the value to the length of a structure or an instance of a buffer into which result columns will be bound.

If a length is specified, it must include space for all of the bound columns and any padding of the structure or buffer to ensure that when the address of a bound column is incremented with the specified length, the result will point to the beginning of the same column in the next row. When using the sizeof operator with structures or unions in ANSI C, this behavior is guaranteed.

Column-wise binding is the default binding orientation for SQLFetch and SQLFetchScroll.

For more information, see Binding Columns for Use with Block Cursors.

Setting this statement attribute sets the SQL_DESC_BIND_TYPE field in the ARD header.
SQL_ATTR_ROW_NUMBER (ODBC 2.0) An SQLULEN value that is the number of the current row in the entire result set. If the number of the current row cannot be determined or there is no current row, the driver returns 0.

This attribute can be retrieved by a call to SQLGetStmtAttr but not set by a call to SQLSetStmtAttr.
SQL_ATTR_ROW_OPERATION_PTR (ODBC 3.0) An SQLUSMALLINT * value that points to an array of SQLUSMALLINT values used to ignore a row during a bulk operation using SQLSetPos. Each value is set to either SQL_ROW_PROCEED (for the row to be included in the bulk operation) or SQL_ROW_IGNORE (for the row to be excluded from the bulk operation). (Rows cannot be ignored by using this array during calls to SQLBulkOperations.)

This statement attribute can be set to a null pointer, in which case the driver does not return row status values. This attribute can be set at any time, but the new value is not used until the next time SQLSetPos is called.

For more information, see Updating Rows in the Rowset with SQLSetPos and Deleting Rows in the Rowset with SQLSetPos.

Setting this statement attribute sets the SQL_DESC_ARRAY_STATUS_PTR field in the ARD.
SQL_ATTR_ROW_STATUS_PTR (ODBC 3.0) An SQLUSMALLINT * value that points to an array of SQLUSMALLINT values containing row status values after a call to SQLFetch or SQLFetchScroll. The array has as many elements as there are rows in the rowset.

This statement attribute can be set to a null pointer, in which case the driver does not return row status values. This attribute can be set at any time, but the new value is not used until the next time SQLBulkOperations, SQLFetch, SQLFetchScroll, or SQLSetPos is called.

For more information, see Number of Rows Fetched and Status.

Setting this statement attribute sets the SQL_DESC_ARRAY_STATUS_PTR field in the IRD header.

This attribute is mapped by an ODBC 2.x driver to the rgbRowStatus array in a call to SQLExtendedFetch.
SQL_ATTR_ROWS_FETCHED_PTR (ODBC 3.0) An SQLULEN * value that points to a buffer in which to return the number of rows fetched after a call to SQLFetch or SQLFetchScroll; the number of rows affected by a bulk operation performed by a call to SQLSetPos with an Operation argument of SQL_REFRESH; or the number of rows affected by a bulk operation performed by SQLBulkOperations. This number includes error rows.

For more information, see Number of Rows Fetched and Status.

Setting this statement attribute sets the SQL_DESC_ROWS_PROCESSED_PTR field in the IRD header.

If the call to SQLFetch or SQLFetchScroll that fills in the buffer pointed to by this attribute does not return SQL_SUCCESS or SQL_SUCCESS_WITH_INFO, the contents of the buffer are undefined.
SQL_ATTR_SIMULATE_CURSOR (ODBC 2.0) An SQLULEN value that specifies whether drivers that simulate positioned update and delete statements guarantee that such statements affect only one single row.

To simulate positioned update and delete statements, most drivers construct a searched UPDATE or DELETE statement containing a WHERE clause that specifies the value of each column in the current row. Unless these columns make up a unique key, such a statement can affect more than one row.

To guarantee that such statements affect only one row, the driver determines the columns in a unique key and adds these columns to the result set. If an application guarantees that the columns in the result set make up a unique key, the driver is not required to do so. This may reduce execution time.

SQL_SC_NON_UNIQUE = The driver does not guarantee that simulated positioned update or delete statements will affect only one row; it is the application's responsibility to do so. If a statement affects more than one row, SQLExecute, SQLExecDirect, or SQLSetPos returns SQLSTATE 01001 (Cursor operation conflict).

SQL_SC_TRY_UNIQUE = The driver attempts to guarantee that simulated positioned update or delete statements affect only one row. The driver always executes such statements, even if they might affect more than one row, such as when there is no unique key. If a statement affects more than one row, SQLExecute, SQLExecDirect, or SQLSetPos returns SQLSTATE 01001 (Cursor operation conflict).

SQL_SC_UNIQUE = The driver guarantees that simulated positioned update or delete statements affect only one row. If the driver cannot guarantee this for a given statement, SQLExecDirect or SQLPrepare returns an error.

If the data source provides native SQL support for positioned update and delete statements and the driver does not simulate cursors, SQL_SUCCESS is returned when SQL_SC_UNIQUE is requested for SQL_SIMULATE_CURSOR. SQL_SUCCESS_WITH_INFO is returned if SQL_SC_TRY_UNIQUE or SQL_SC_NON_UNIQUE is requested. If the data source provides the SQL_SC_TRY_UNIQUE level of support and the driver does not, SQL_SUCCESS is returned for SQL_SC_TRY_UNIQUE and SQL_SUCCESS_WITH_INFO is returned for SQL_SC_NON_UNIQUE.

If the specified cursor simulation type is not supported by the data source, the driver substitutes a different simulation type and returns SQLSTATE 01S02 (Option value changed). For SQL_SC_UNIQUE, the driver substitutes, in order, SQL_SC_TRY_UNIQUE or SQL_SC_NON_UNIQUE. For SQL_SC_TRY_UNIQUE, the driver substitutes SQL_SC_NON_UNIQUE.

The default is SQL_SC_UNIQUE.

For more information, see Simulating Positioned Update and Delete Statements.
SQL_ATTR_USE_BOOKMARKS (ODBC 2.0) An SQLULEN value that specifies whether an application will use bookmarks with a cursor:

SQL_UB_OFF = Off (the default)

SQL_UB_VARIABLE = An application will use bookmarks with a cursor, and the driver will provide variable-length bookmarks if they are supported. SQL_UB_FIXED is deprecated in ODBC 3.x. ODBC 3.x applications should always use variable-length bookmarks, even when working with ODBC 2.x drivers (which supported only 4-byte, fixed-length bookmarks). This is because a fixed-length bookmark is just a special case of a variable-length bookmark. When working with an ODBC 2.x driver, the Driver Manager maps SQL_UB_VARIABLE to SQL_UB_FIXED.

To use bookmarks with a cursor, the application must specify this attribute with the SQL_UB_VARIABLE value before opening the cursor.

For more information, see Retrieving Bookmarks.

[1] These functions can be called asynchronously only if the descriptor is an implementation descriptor, not an application descriptor.

See Column-Wise Binding and Row-Wise Binding.

For information about See
Canceling statement processing SQLCancel Function
Returning the setting of a connection attribute SQLGetConnectAttr Function
Returning the setting of a statement attribute SQLGetStmtAttr Function
Setting a connection attribute SQLSetConnectAttr Function
Setting a single field of the descriptor SQLSetDescField Function

See Also

ODBC API Reference
ODBC Header Files