SQLGetConnectAttr function (CLI) - Get current attribute setting
Returns the current setting of a connection attribute.
Specification:
- CLI 5.0
- ODBC 3.0
- ISO CLI
Syntax
SQLRETURN SQLGetConnectAttr(SQLHDBC ConnectionHandle,
SQLINTEGER Attribute,
SQLPOINTER ValuePtr,
SQLINTEGER BufferLength,
SQLINTEGER *StringLengthPtr);
Function arguments
Data type | Argument | Use | Description |
---|---|---|---|
SQLHDBC | ConnectionHandle | input | Connection handle. |
SQLINTEGER | Attribute | input | Attribute to retrieve. |
SQLPOINTER | ValuePtr | output | A pointer to memory in which to return the current value of the attribute specified by Attribute. |
SQLINTEGER | BufferLength | input |
|
SQLINTEGER * | 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 BufferLength minus the length of the null-termination character, the data in *ValuePtr is truncated to BufferLength minus the length of the null-termination character and is null-terminated by CLI. |
Usage
If Attribute specifies an attribute that returns a string, ValuePtr must be a pointer to a buffer for the string. The maximum length of the string, including the null termination character, will be BufferLength bytes.
Depending on the attribute, an application does not need to establish a connection before calling SQLGetConnectAttr(). However, if SQLGetConnectAttr() is called and the specified attribute does not have a default and has not been set by a prior call to SQLSetConnectAttr(), SQLGetConnectAttr() will return SQL_NO_DATA.
If Attribute is SQL_ATTR_TRACE or SQL_ATTR_TRACEFILE, ConnectionHandle does not have to be valid, and SQLGetConnectAttr() will not return SQL_ERROR if ConnectionHandle is invalid. These attributes apply to all connections. SQLGetConnectAttr() will return SQL_ERROR if another argument is invalid.
While an application can set statement attributes using SQLSetConnectAttr(), an application cannot use SQLGetConnectAttr() to retrieve statement attribute values; it must call SQLGetStmtAttr() to retrieve the setting of statement attributes.
The SQL_ATTR_AUTO_IPD connection attribute can be returned by a call to SQLGetConnectAttr(), but cannot be set by a call to SQLSetConnectAttr().
Return codes
- SQL_SUCCESS
- SQL_SUCCESS_WITH_INFO
- SQL_NO_DATA
- SQL_ERROR
- SQL_INVALID_HANDLE
Diagnostics
SQLSTATE | Description | Explanation |
---|---|---|
01000 | Warning. | Informational message. (Function returns SQL_SUCCESS_WITH_INFO.) |
01004 | Data 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.) |
08003 | Connection is closed. | An Attribute value was specified that required an open connection. |
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. |
HY010 | Function sequence error. | SQLBrowseConnect() was called for the ConnectionHandle and returned SQL_NEED_DATA. This function was called before SQLBrowseConnect() returned SQL_SUCCESS_WITH_INFO or SQL_SUCCESS. |
HY090 | Invalid string or buffer length. | The value specified for the argument BufferLength was less than 0. |
HY092 | Option type out of range. | The value specified for the argument Attribute was not valid. |
HYC00 | Driver not capable. | The value specified for the argument Attribute was a valid connection or statement attribute for the version of the CLI driver, but was not supported by the data source. |
Restrictions
None.
Example
SQLINTEGER autocommit;
/* ... */
/* get the current setting for the AUTOCOMMIT attribute */
cliRC = SQLGetConnectAttr(hdbc, SQL_ATTR_AUTOCOMMIT, &autocommit, 0, NULL);