SQLSetConnectAttr--Set options related to a connection

Purpose

Specification: DB2 CLI ODBC 1.0 ISO CLI

SQLSetConnectAttr() sets options related to a connection.

Syntax

SQLRETURN   SQLSetConnectAttr   (SQLHDBC        ConnectionHandle,   
                              SQLINTEGER        Attribute,         
                              SQLPOINTER        ValuePtr,          
                              SQLINTEGER        StringLength);     

Function arguments

Table 80. SQLSetConnectAttr arguments

Data type Argument Use Description
SQLHDBC ConnectionHandle input Connection handle.
SQLINTEGER Attribute input Option to set.
SQLPOINTER ValuePtr 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, StringLength is ignored.

If Attribute is a DB2 CLI attribute, the application indicates the nature of the attribute by setting the StringLength argument. StringLength can have the following values:

  • If ValuePtr is a pointer to a character string, StringLength is the length of the string or SQL_NTS.
  • If ValuePtr is a pointer to a binary buffer, the application places the result of the SQL_LEN_BINARY_ATTR(length) macro in StringLength. This places a negative value in StringLength.
  • If ValuePtr is a pointer to a value other than a character string or a binary string, StringLength should have the value SQL_IS_POINTER.
  • If ValuePtr contains a fixed-length value, StringLength is either SQL_IS_INTEGER or SQL_IS_UINTEGER, as appropriate.
SQLINTEGER StringLength input If ValuePtr points to a character string or a binary buffer, this argument should be the length of ValuePtr. If ValuePtr is a pointer, but not to a string or binary buffer, StringLength should have the value SQL_IS_POINTER. If ValuePtr is not a pointer, StringLength should have the value SQL_IS_NOT_POINTER.

Usage

Connection attributes for a connection remain in effect until they are changed by another call to SQLSetConnectAttr() or the connection is dropped by calling SQLDisconnect().

SQLSetConnectAttr() accepts attribute information in one of two different formats: a null-terminated character string or a 32-bit integer value. The format of each is noted in the attribute's description. Character strings pointed to by the ValuePtr argument of SQLSetConnectAttr() have a length of StringLength.

Connection attributes

The currently defined attributes are shown below.

SQL_ATTR_AUTOCOMMIT (DB2 CLI/ODBC)
A 32-bit integer value that specifies the mode type. The supported values are:

SQL_ATTR_CONNECTION_DEAD (DB2 CLI/ODBC)
A READ ONLY 32-bit integer value that indicates whether or not the connection is still active. DB2 CLI will return one of the following values:

SQL_ATTR_LOGIN_TIMEOUT (DB2 CLI/ODBC)
A 32-bit integer value corresponding to the number of seconds to wait for a login request to complete before returning control to the application.

SQL_ATTR_FILENAME_FORMAT (DB2 Everyplace)
A 32-bit integer specifies whether DB2e database engine should create filenames in long or 8.3 format. Applications are allowed to change filename format only if no catalog files exist in the path connected when SQLSetConnectAttr is invoked. SQL_ERROR with SQLState HY000 will be returned if changing filename format is denied due to pre-existing catalog files. For example, if an application connects to a path where DB2 Everyplace catalog files already exist, any attempts to change filename format will fail. If an application connects to a path where no DB2 Everyplace catalog files exist and it attempts to change filename format after the first CREATE TABLE statement, SQLSetConnectAttr will return SQL_ERROR too. This is because catalog files are created during the very first CREATE TABLE statement, and it is not allowed to change filename format after the creation of catalog files. The default filename format is platform dependent. SQL_FILENAME_FORMAT_LONG is currently the default for all platforms supported.

Attribute values:

 SQL_FILENAME_FORMAT_LONG - files will be created in long filename format. 
 SQL_FILENAME_FORMAT_83- files will be created in 8.3 filename format. 

Return codes

Diagnostics

Table 81. SQLSetConnectAttr SQLSTATEs

SQLSTATE Description Explanation
HY000 General error. Filename format cannot be changed.
HY001 Memory allocation failure. DB2 CLI is unable to allocate memory required to support execution or completion of the function.
HY014 No more handles. DB2 CLI was unable to allocate a handle due to internal resources.
HY090 Invalid string or buffer length. The value of one of the name length arguments was less than 0, but not equal to SQL_NTS.

Restrictions

Related reference