SQLSetConnectAttr - Set a connection attribute
SQLSetConnectAttr()
sets
connection attributes for a particular connection.
Syntax
SQLRETURN SQLSetConnectAttr (SQLHDBC hdbc,
SQLINTEGER fAttr,
SQLPOINTER vParam,
SQLINTEGER sLen);
Function arguments
Data type | Argument | Use | Description |
---|---|---|---|
SQLHDBC | hdbc | Input | Connection handle. |
SQLINTEGER | fAttr | Input | Connect attribute to set, refer to Table 2 for more information. |
SQLPOINTER | vParam | Input | Value associated with fAttr. Depending on the option, this can be a pointer to a 32-bit integer value, or a character string. |
SQLINTEGER | sLen | Input | Length of input value, if it is a character string; otherwise, unused. |
Usage
All connection and statement options
set through the SQLSetConnectAttr()
persist until SQLFreeConnect()
is
called or the next SQLSetConnectAttr()
call.
The format of information set through vParam depends on the specified fAttr. The option information can be either a 32-bit integer or a pointer to a null-terminated character string.
fAttr | Contents |
---|---|
SQL_ATTR_2ND_LEVEL_TEXT | A 32-bit integer value:
|
SQL_ATTR_AUTOCOMMIT | A 32-bit value that sets the commit
behavior for the connection. These are the possible values:
|
SQL_ATTR_CONCURRENT_ACCESS_RESOLUTION | A 32-bit integer value that specifies
the concurrent access resolution to use at the statement level. This
attribute only applies to the transaction isolation level of Cursor
Stability or Read Stability, otherwise, it is ignored. These are the
possible values :
|
SQL_ATTR_CONN_SORT_SEQUENCE | A 32-bit integer
value that specifies the sort sequence to use with the connection.
The possible values are:
The distinction between SQL_JOB_SORT_SEQUENCE and SQL_JOBRUN_SORT_SEQUENCE will only be seen when running in server-mode. In that case, the SQL_JOBRUN_SORT_SEQUENCE will cause the effective sort sequence of the server-mode job to be used, rather the front-end job where the CLI is being executed. |
SQL_ATTR_COMMIT
or SQL_TXN_ISOLATION |
A 32-bit value that
sets the transaction-isolation level for the current connection referenced
by hdbc. The following values are accepted by Db2 for
i CLI, but each data source might only support some of these isolation
levels:
In IBM® terminology,
For a detailed explanation of isolation levels, refer to the Db2 for i SQL Reference. |
SQL_ATTR_CURRENT_IMPLICIT_XMLPARSE_OPTION | A null-terminated
character string that is the string constant used to set the CURRENT
IMPLICIT XMLPARSE OPTION special register. Setting this attribute causes the SET CURRENT IMPLICIT XMLPARSE OPTION SQL statement to be issued. If this attribute is set before a connection has been established, the SET CURRENT IMPLICIT XMLPARSE OPTION SQL statement will be issued when the connection is made. The valid values include:
The default value of the CURRENT IMPLICIT XMLPARSE OPTION special register is 'STRIP WHITESPACE'. |
SQL_ATTR_DATE_FMT | A 32-bit integer value:
|
SQL_ATTR_DATE_SEP | A 32-bit integer value:
Separators only apply to the following SQL_ATTR_DATE_FMT attribute types:
|
SQL_ATTR_DBC_DEFAULT_LIB | A character value that indicates the default library that is used for resolving unqualified file references. |
SQL_ATTR_DBC_SYS_NAMING | A 32-bit integer value:
|
SQL_ATTR_DECFLOAT_ROUNDING_MODE | A 32-bit integer value:
Specifying this attribute causes the decimal floating point
rounding mode to be set in the following manner:
Applications should avoid setting the rounding mode using an SQL statement. Using the SET CURRENT DECFLOAT ROUNDING MODE statement will have no effect on the current connection if a local connection has been made. Executing the SQL statement for a remote connection will change the rounding mode for the application server, but will not affect the rounding mode in the application requestor job. |
SQL_ATTR_DECIMAL_SEP | A 32-bit integer value:
|
SQL_ATTR_EXTENDED_COL_INFO | A 32-bit integer value:
|
SQL_ATTR_EXTENDED_INDICATORS | A 32-bit integer value:
|
SQL_ATTR_FREE_LOCATORS | A pointer to an array of 32-bit integer values
containing the locator handles to be freed. The sLen parameter
indicates the number of locators to be freed. A special value of '-99' for the sLen parameter indicates that all locators and locator storage that has been allocated up to that point in the connection should be freed. A non-null pointer to the array of locator handles must still be passed, though it is not used. |
SQL_ATTR_HEX_LITERALS | A 32-bit integer value:
|
SQL_ATTR_INFO_ACCTSTR | A character value used to identify the client
accounting string that is sent to the host database server at connect
time. Db2 for
i servers
support a length of up to 255 characters. When the value is being set, some servers might not handle the entire length provided and might truncate the value. To ensure that the data is converted correctly when transmitted to a host system, use only the characters A to Z, 0 to 9, and the underscore (_) or period (.). |
SQL_ATTR_INFO_APPLNAME | A character value used to identify the client
application name that is sent to the host database server at connect
time.Db2 for
i servers
support a length of up to 255 characters. When the value is being set, some servers might not handle the entire length provided and might truncate the value. To ensure that the data is converted correctly when transmitted to a host system, use only the characters A to Z, 0 to 9, and the underscore (_) or period (.). |
SQL_ATTR_INFO_PROGRAMID | A character value used to identify the client
program name that is sent to the host database server at connect time.Db2 for
i servers support
a length of up to 255 characters. When the value is being set, some servers might not handle the entire length provided and might truncate the value. To ensure that the data is converted correctly when transmitted to a host system, use only the characters A to Z, 0 to 9, and the underscore (_) or period (.). |
SQL_ATTR_INFO_USERID | A character value used to identify the client
user-id that is sent to the host database server at connect time.Db2 for
i servers support
a length of up to 255 characters. When the value is being set, some servers might not handle the entire length provided and might truncate the value. This user-id is not to be confused with the authentication user-id. This user-id is for identification purposes only and is not used for any authorization. To ensure that the data is converted correctly when transmitted to a host system, use only the characters A to Z, 0 to 9, and the underscore (_) or period (.). |
SQL_ATTR_INFO_WRKSTNNAME | A character value used to identify the client
workstation name that is sent to the host database server at connect
time. Db2 for
i servers
support a length of up to 255 characters. When the value is being set, some servers might not handle the entire length provided and might truncate the value. To ensure that the data is converted correctly when transmitted to a host system, use only the characters A to Z, 0 to 9, and the underscore (_) or period (.). |
SQL_ATTR_MAX_PRECISION | ![]() ![]() |
SQL_ATTR_MAX_SCALE | ![]() ![]() |
SQL_ATTR_MIN_DIVIDE_SCALE | ![]() ![]() |
SQL_ATTR_OLD_MTADTA_BEHAVIOR | A 32-bit integer value:
SQLTables , SQLColumns() ,
and SQLStatistics() . |
SQL_ATTR_NULLT_ARRAY_RESULTS | A 32-bit integer value:
|
SQL_ATTR_NULLT_OUTPUT_PARMS | A 32-bit integer value:
|
SQL_ATTR_QUERY_OPTIMIZE_GOAL |
A 32-bit integer value that tells the optimizer
to behave in a specified way when processing a query:
|
SQL_ATTR_SAVEPOINT_NAME | A character value that indicates the savepoint
name to be used by SQLEndTran() on the functions
SQL_SAVEPOINT_NAME_ROLLBACK or SQL_SAVEPOINT_NAME_RELEASE. |
SQL_ATTR_SERVERMODE_SUBSYSTEM | A null terminated character string that is used to specify the subsystem in which the associated QSQSRVR jobs will run. The default behavior is to have the jobs run in the QSYSWRK subsystem. If the value *SAME is used, then the QSQSRVR jobs will run in the same subsystem as the job using the CLI API. |
SQL_ATTR_TIME_FMT | A 32-bit integer value:
|
SQL_ATTR_TIME_SEP | A 32-bit integer value:
|
SQL_ATTR_TIMESTAMP_PREC | A 32-bit integer value:
|
SQL_ATTR_TXN_EXTERNAL |
A 32-bit integer value that must be SQL_TRUE to enable the use of XA transaction setting in the CLI connection. SQL_ATTR_TXN_EXTERNAL must be set to SQL_TRUE to use the XA transaction options by the SQL_ATTR_TXN_INFO connection attribute. The default is SQL_FALSE, which is not to enable XA transaction support. However, as soon as transaction support is enabled for the connection, it cannot be disabled. (Attempting to set SQL_ATTR_TXN_EXTERNAL to SQL_FALSE results in a CLI error.) Further information as well as an example of use of the SQL_ATTR_TXN_EXTERNAL connection attribute can be found in Example: Using the CLI XA transaction connection attributes. |
SQL_ATTR_TXN_INFO |
A 32-bit integer value:
Use of this connection attribute requires the user to be running in server mode. Keep in mind, a user cannot toggle between a non-server mode and server mode environment. The input argument vParam must point to a TXN_STRUCT object. This structure can be found in the header file QSYSINC/h.SQLCLI. The xa_info argument for the xa_open XA API must include the
THDCTL=C keyword and value when using See XA transaction support for commitment control in the Commitment control topic for more information about XA transactions. See XA APIs for more information. See Example: Using the CLI XA transaction connection attributes for more information and an example that shows how you can use the SQL_ATTR_TXN_INFO connection attribute. |
SQL_ATTR_TXN_INFO (continued) |
When running XA calls through CLI, the return codes from CLI reflect the XA return code specifications. These values can be found in the XA specification documentation, as well as in the XA.h include file. Note that the return code values that are listed in the XA include file take precedence over the CLI return code values when calling XA through this connection attribute. |
SQL_ATTR_UCS2 | A 32-bit integer value:
|
SQL_ATTR_XML_DECLARATION | A 32-bit unsigned integer that specifies
which elements of an XML declaration are added to XML data when it
is implicitly serialized. This attribute does not affect the result
of the XMLSERIALIZE function. Set this attribute to the sum of each
component required:
Attempts to set any other value using |
Return codes
- SQL_SUCCESS
- SQL_SUCCESS_WITH_INFO
- SQL_ERROR
- SQL_INVALID_HANDLE
Diagnostics
SQLSTATE | Description | Explanation |
---|---|---|
HY001 | Memory allocation failure | The driver is unable to allocate memory required to support the processing or completion of the function. |
HY009 | Argument value that is not valid | Given the fAttr value, a value
that is not valid is specified for the argument vParam. An fAttr that is not valid value is specified. |