Conformance
Version Introduced:ODBC 3.0
Standards Compliance:ISO 92
Summary
SQLGetStmtAttr returns the current setting of a statement attribute.
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” in Chapter 17, “Programming Considerations.”
Syntax
SQLRETURN SQLGetStmtAttr(
SQLHSTMTStatementHandle,
SQLINTEGERAttribute,
SQLPOINTERValuePtr,
SQLINTEGERBufferLength,
SQLINTEGER *StringLengthPtr);
Arguments
StatementHandle
[Input]
Statement handle.
Attribute
[Input]
Attribute to retrieve.
ValuePtr
[Output]
Pointer to a buffer in which to return the value of the attribute specified in Attribute.
BufferLength
[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, BufferLength is ignored. If the value returned in *ValuePtr is a Unicode string (when calling SQLGetStmtAttrW), the BufferLength argument must be an even number
If Attribute is a driver-defined attribute, the application indicates the nature of the attribute to the Driver Manager by setting the BufferLength argument. BufferLength can have the following values:
StringLengthPtr
[Output]
A pointer to a buffer in which to return the total number of bytes (excluding the null-termination character) available to return in *ValuePtr. If ValuePtr is a null pointer, no length is returned. If the attribute value is a character string, and the number of bytes available to return is greater than or equal to BufferLength, the data in *ValuePtr is truncated to BufferLength minus the length of a null-termination character and is null-terminated by the driver.
Returns
SQL_SUCCESS, SQL_SUCCESS_WITH_INFO, SQL_ERROR, or SQL_INVALID_HANDLE.
Diagnostics
When SQLGetStmtAttr 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 SQLGetStmtAttr 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.) | |||
01004 | String data, right truncated | The data returned in *ValuePtr was truncated to be BufferLength minus the length of a null-termination character. The length of the untruncated string value is returned in *StringLengthPtr. (Function returns SQL_SUCCESS_WITH_INFO.) | |||
24000 | Invalid cursor state | The argument Attribute was SQL_ATTR_ROW_NUMBER and the cursor was not open, or the cursor was positioned before the start of the result set or after the end of the result set. | |||
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 argument MessageText 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) 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. |
|||
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. | |||
HY090 | Invalid string or buffer length | (DM) *ValuePtr is a character string, and BufferLength was less than zero, but not equal to SQL_NTS. | |||
HY092 | Invalid attribute/option identifier | The value specified for the argument Attribute was not valid for the version of ODBC supported by the driver. | |||
HY109 | Invalid cursor position | The Attribute argument was SQL_ATTR_ROW_NUMBER and the row had been deleted or could not be fetched. | |||
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. | |||
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 corresponding to the StatementHandle does not support the function. |
Comments
For general information about statement attributes, see “Statement Attributes” in Chapter 9, “Executing Statements.”
A call to SQLGetStmtAttr returns in *ValuePtr the value of the statement attribute specified in Attribute. That value can either be a 32-bit value or a null-terminated character string. If the value is a null-terminated string, the application specifies the maximum length of that string in the BufferLength argument, and the driver returns the length of that string in the *StringLengthPtr buffer. If the value is a 32-bit value, the BufferLength and StringLengthPtr arguments are not used.
To allow applications calling SQLGetStmtAttr to work with ODBC 2.x drivers, a call to SQLGetStmtAttr is mapped in the Driver Manager to SQLGetStmtOption.
The following statement attributes are read-only, so can be retrieved by SQLGetStmtAttr, but not set by SQLSetStmtAttr. For a list of attributes that can be set and retrieved, see SQLSetStmtAttr.
SQL_ATTR_IMP_PARAM_DESC | SQL_ATTR_ROW_NUMBER |
SQL_ATTR_IMP_ROW_DESC |
Related Functions
For information about | See |
Returning the setting of a connection attribute | SQLGetConnectAttr |
Setting a connection attribute | SQLSetConnectAttr |
Setting a statement attribute | SQLSetStmtAttr |