Specification: | DB2 CLI 2.1 | ISO CLI |
SQLSetEnvAttr() sets an environment attribute for the current environment.
Syntax
SQLRETURN SQLSetEnvAttr (SQLHENV EnvironmentHandle, /* henv */ SQLINTEGER Attribute, SQLPOINTER ValuePtr, /* Value */ SQLINTEGER StringLength);
Function Arguments
Table 164. SQLSetEnvAttr Arguments
Data Type | Argument | Use | Description |
---|---|---|---|
SQLHENV | EnviornmentHandle | Input | Environment handle. |
SQLINTEGER | Attribute | Input | Environment attribute to set, refer to Environment Attributes for the list of attributes and their descriptions. |
SQLPOINTER | ValuePtr | Input | The desired value for Attribute. |
SQLINTEGER | StringLength | Input | Length of ValuePtr in bytes if the attribute value is a character string; if Attribute does not denote a string, then DB2 CLI ignores StringLength. |
Usage
Once set, the attribute's value affects all connections under this environment.
The application can obtain the current attribute value by calling SQLGetEnvAttr().
Connection pooling is enabled by calling SQLSetEnvAttr() to set the SQL_ATTR_CONNECTION_POOLING attribute to SQL_CP_ONE_PER_DRIVER or SQL_CP_ONE_PER_HENV. This call must be made before the application allocates the shared environment for which connection pooling is to be enabled. The environment handle in the call to SQLSetEnvAttr() is set to null, which makes SQL_ATTR_CONNECTION_POOLING a process-level attribute. After connection pooling is enabled, the application then allocates an implicit shared environment by calling SQLAllocHandle() with the InputHandle argument set to SQL_HANDLE_ENV.
After connection pooling has been enabled and a shared environment has been selected for an application, SQL_ATTR_CONNECTION_POOLING cannot be reset for that environment, since SQLSetEnvAttr() is called with a null environment handle when setting this attribute. If this attribute is set while connection pooling is already enabled on a shared environment, the attribute only affects shared environments that are allocated subsequently.
The current setting of the SQL_ATTR_SYNC_POINT attribute is ignored.
This is the default.
This attribute must be set before allocating any connection handles, otherwise, the SQLSetEnvAttr() call will be rejected.
All the connections within an application must have the same SQL_ATTR_CONNECTTYPE and SQL_ATTR_SYNC_POINT values. This attribute can also be set using the SQLSetConnectAttr function. We recommend that the application set the SQL_ATTR_CONNECTTYPE attribute at the environment level rather than on a per connection basis. ODBC applications written to take advantage of coordinated DB2 transactions must set these attributes at the connection level for each connection using SQLSetConnectAttr() as SQLSetEnvAttr() is not supported in ODBC.
Note: | This is an IBM defined extension. |
The following values are used to set the value of this attribute:
This can be used as a governor for the maximum number of connections on a per application basis.
On OS/2, if the NetBIOS protocol is in use, this value corresponds to the number of connections (NetBIOS sessions) that will be concurrently set up by the application. The range of values for OS/2 NetBIOS is 1 to 254. Specifying 0 (the default) will result in 5 reserved connections. Reserved NetBIOS sessions cannot be used by other applications. The number of connections specified by this parameter will be applied to any adaptor that the DB2 NetBIOS protocol uses to connect to the remote server (adapter number is specified in the node directory for a NetBIOS node).
The value that is in effect when the first connection is established is the value that will be used. Once the first connection has been established, attempts to change this value will be rejected. We recommended that the application set SQL_ATTR_MAXCONN at the environment level rather then on a connection basis. ODBC applications must set this attribute at the connection level since SQLSetEnvAttr() is not supported in ODBC.
Note: | This is an IBM defined extension. |
It is recommended that all DB2 CLI applications set this environment attribute. ODBC applications must set this environment attribute before calling any function that has an SQLHENV argument, or the call will return SQLSTATE HY010 (Function sequence error.).
The following values are used to set the value of this attribute:
This is the default.
The CLI functions affected by this attribute are all functions called for the environment (and for any connections and statements allocated under the environment) that have character string parameters.
This attribute can only be set when there are no connection handles allocated under this environment.
The call to SQLSetEntAttr() must have the EnvironmentHandle argument set to SQL_NULL_HANDLE. The settings remain in effect for the life of the process. Generally this attribute is only used for performance sensitive applications, where large numbers of CLI function calls are being made. Before setting any of these bits, ensure that the application, and any other libraries that the application calls, comply with the restrictions listed.
The following values may be combined to form a bitmask:
Refer to the SQL Reference for more information on distributed unit of work (transactions).
All the connections within an application must have the same SQL_ATTR_CONNECTTYPE and SQL_ATTR_SYNC_POINT values. This attribute can also be set using the SQLSetConnectAttr() function. We recommend that the application set these two attributes at the environment level rather than on a per connection basis. ODBC applications written to take advantage of coordinated DB2 transactions must set these attributes at the connection level for each connection using SQLSetConnectAttr() as SQLSetEnvAttr() is not supported in ODBC.
Note: | This is an IBM extension. In embedded SQL, there is an additional sync point setting called SYNCPOINT NONE. This is more restrictive than the SQL_CONCURRENT_TRANS setting of the SQL_ATTR_CONNECTTYPE attribute because SYNCPOINT NONE does not allow for multiple connections to the same database. As a result, it is not necessary for DB2 CLI to support SYNCPOINT NONE. |
For more information on the descriptor field please see SQLSetDescField - Set a Single Field of a Descriptor Record.
This attribute can be set at any time and will take effect the next time a descriptor function is called. It does not affect the StrLen_or_IndPtr value for SQLGetData() calls.
Note: | This is an IBM defined extension. |
A 32-bit integer value that specifies whether the column name is sent over the network and returned on calls to SQLDescribeCol(), SQLColAttribute(), and SQLGetDescField(). The possible values are:
Note: | This is an IBM defined extension. |
Return Codes
Diagnostics
Table 165. SQLSetEnvAttr SQLSTATEs
SQLSTATE | Description | Explanation |
---|---|---|
HY009 | Invalid argument value. | Given the fOption value, an invalid value was specified for the argument vParam. |
HY011 | Operation invalid at this time. | Applications cannot set environment attributes while connection handles are allocated on the environment handle. |
HY024 | Invalid attribute value | Given the specified Attribute value, an invalid value was specified in *ValuePtr. |
HY090 | Invalid string or buffer length | The StringLength argument was less than 0, but was not SQL_NTS. |
HY092 | Option type out of range. | An invalid Attribute value was specified. |
HYC00 | Driver not capable. | The specified Attribute is not supported by DB2 CLI.
Given specified Attribute value, the value specified for the argument ValuePtr is not supported. |
Restrictions
None.
(The complete sample pcall.c is also available here .)
/* From the CLI sample PCALL.C */ /* ... */ /* enable sending column names over the network */ sqlrc = SQLSetEnvAttr( henv, SQL_ATTR_USE_LIGHT_OUTPUT_SQLDA, ( SQLPOINTER ) SQL_FALSE, SQL_FALSE ) ;
References