Call Level Interface Guide and Reference

Environment, Connection, and Statement Attributes

Environments, connections, and statements each have a defined set of attributes (or options). All attributes can be queried by the application, but only some attributes can be changed from their default values. By changing attribute values, the application can change the behavior of DB2 CLI.

An environment handle has attributes which affect the behavior of DB2 CLI functions under that environment. The application can specify the value of an attribute by calling SQLSetEnvAttr() and can obtain the current attribute value by calling SQLGetEnvAttr(). SQLSetEnvAttr() can only be called before connection handles have been allocated.

A connection handle has attributes which affect the behavior of DB2 CLI functions under that connection. Of the attributes that can be changed:

The application can change the value of connection attributes by calling SQLSetConnectAttr() and can obtain the current value of an attribute by calling SQLGetConnectAttr(). An example of a connection attribute which can be set any time after a handle is allocated is the auto-commit option introduced in Commit or Rollback. For complete details on when each attribute can be set, refer to SQLSetConnectAttr - Set Connection Attributes.

A statement handle has attributes which affect the behavior of CLI functions executed using that statement handle. Of the statement attributes that can be changed:

The application can specify the value of any settable statement attribute by calling SQLSetStmtAttr(), and can obtain the current value of an attribute by calling SQLGetStmtAttr(). For complete details on when each attribute can be set, refer to SQLSetStmtAttr - Set Options Related to a Statement.

The SQLSetConnectAttr() function cannot be used to set statement attributes. This was supported in versions of DB2 CLI prior to version 5; see Setting a Subset of Statement Attributes using SQLSetConnectAttr() for details.

Many applications use just the default attribute settings; however, there may be situations where some of these defaults are not suitable for a particular user of the application. DB2 CLI provides end users with two methods to change some of these default values at run time. The first method is to specify the new default attribute value(s) in the connection string input to the SQLDriverConnect() and SQLBrowseConnect() functions. The second method involves the specification of the new default attribute value(s) in a DB2 CLI initialization file.

The DB2 CLI initialization file can be used to change default values for all DB2 CLI applications on that workstation. This may be the end user's only means of changing the defaults if the application does not provide a means for the user to provide default attribute values in the SQLDriverConnect() connection string. Default attribute values that are specified on SQLDriverConnect() override the values in the DB2 CLI initialization file for that particular connection. For information on how the end user can use the DB2 CLI initialization file as well as for a list of changeable defaults, refer to DB2 CLI/ODBC Configuration Keyword Listing.

The mechanisms for changing defaults are intended for end user tuning; application developers must use the appropriate set-attribute function. If an application does call a set-attribute or option function with a value different from the initialization file or the connection string specification, then the initial default value is overridden and the new value takes effect.

The attributes that can be changed are listed in the detailed function descriptions of the set attribute or option functions, see Chapter 5, DB2 CLI Functions. The readonly options (if any exist) are listed with the detailed function descriptions of the get attribute or option functions.

For information on some commonly used attributes, refer to Appendix A, Programming Hints and Tips.

The diagram below shows the addition of the attribute functions to the basic connect scenario.

Figure 4. Setting and Retrieving Attributes (Options)


Setting and Retrieving Attributes (Options)


[ Top of Page | Previous Page | Next Page ]