Call Level Interface Guide and Reference

SQLSetEnvAttr - Set Environment Attribute

Purpose
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().

Environment Attributes

SQL_ATTR_CONNECTION_POOLING
32-bit integer value that enables or disables connection pooling at the environment level. The following values are used:

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.

SQL_ATTR_CONNECTTYPE
A 32-bit integer value that specifies whether this application is to operate in a coordinated or uncoordinated distributed environment. If the processing needs to be coordinated, then this option must be considered in conjunction with the SQL_ATTR_SYNC_POINT connection option. The possible values are:

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.

SQL_ATTR_CP_MATCH
A 32-bit value that determines how a connection is chosen from a connection pool. When SQLConnect() or SQLDriverConnect() is called, DB2 CLI (or the Driver Manager when used) determines which connection is reused from the pool. DB2 CLI (or the Driver Manager) attempts to match the connection options in the call and the connection attributes set by the application to the keywords and connection attributes of the connections in the pool. The value of this attribute determines the level of precision of the matching criteria.

The following values are used to set the value of this attribute:

SQL_ATTR_MAXCONN
A 32-bit integer value corresponding to the number that maximum concurrent connections that an application may desire to set up. The default value is 0, which means no maximum - the application is allowed to set up as many connections as the system resources permit. The integer value must be 0 or a positive number.

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.

SQL_ATTR_ODBC_VERSION
A 32-bit integer that determines whether certain functionality exhibits ODBC 2.x (DB2 CLI v2) behavior or ODBC 3.0 (DB2 CLI v5) behavior.

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:

SQL_ATTR_OUTPUT_NTS
A 32-bit integer value which controls the use of null-termination in output arguments. The possible values are:

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.

SQL_ATTR_PROCESSCTRL
A 32-bit mask that sets process level attributes which affect all environments and connections for the process. This attribute must be set before the environment handle is allocated.

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:

SQL_ATTR_SYNC_POINT
A 32-bit integer value that allows the application to choose between one-phase coordinated transactions and two-phase coordinated transactions. The possible values are:

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.

SQL_ATTR_USE_2BYTES_OCTET_LENGTH
A 4-byte integer value that specifies whether the SQL_DESC_OCTET_LENGTH_PTR descriptor field (used as either an APD or ARD) is a pointer to a 2 byte value or a 4 byte value (default). The possible values are:

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.

SQL_ATTR_USE_LIGHT_OUTPUT_SQLDA

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.

SQL_CONNECTTYPE
This Attribute has been replaced with SQL_ATTR_CONNECTTYPE.

SQL_MAXCONN
This Attribute has been replaced with SQL_ATTR_MAXCONN.

SQL_SYNC_POINT
This Attribute has been replaced with SQL_ATTR_SYNC_POINT.

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.

CLI Sample pcall.c

(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


[ Top of Page | Previous Page | Next Page ]