Skip to content

SQLSetConnectAttr

SQLSetConnectAttr#

SQLSetConnectAttr() sets attributes that govern aspects of connections.

SQLSetConnectAttrW() as a Unicode string supports same execution as SQLSetConnectAttr().

Syntax#

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

Arguments#

Data Type Argument In/Output Description
SQLHDBC dbc Input Connection handle
SQLINTEGER Attribute Input Attribute to set
SQLPOINTER ValuePtr Input Pointer of value contaied attribute.
Depending on the Attribute value, the ValuePtr will be either a 32-bit unsigned integer or a pointer indicating the Nullterminator string.
- SQL_ATTR_AUTOCOMMIT
- SQL_ATTR_CONNECTION_TIMEOUT
- SQL_ATTR_PORT
- SQL_ATTR_TXN_ISOLATION
- ALTIBASE_APP_INFO
- ALTIBASE_DATE_FORMAT
SQLINTEGER StringLength Input When ValuePtr is the character string, StringLength is the length of the character string or SQL_NTS.
If ValuePtr is 32-bit integer, this argument is ignored.

Return Values#

SQL_SUCCESS
SQL_SUCCESS_WITH_INFO
SQL_INVALID_HANDLE
SQL_ERROR

Description#

An application can call SQLSetConnectAttr() at any point whether the connection is allocated or released. All connections successfully set by an application and statement attribute are stored until SQLFreeHandle() is called in the current connection

Attribute Contents
SQL_ATTR_AUTOCOMMIT 32-bit value to set the commit mode.
- SQL_AUTOCOMMIT_ON: Each SQL statement is automatically committed.
- SQL_AUTOCOMMIT_OFF: Not automatically committed.
SQL_ATTR_CONNECTION_TIMEOUT Set timeout value to prevent blocking that may occur in select() or poll() in an unstable network
SQL_ATTR_PORT Server port setting (32-bit Integer)
SQL_ATTR_TXN_ISOLATION 32-bit value that sets the transaction isolation level for the current connection referred to by dbc.
SQL_ATTR_ENLIST_IN_DTC Participate in a distributed transaction initiated by a Distributed Transaction Coordinator (DTC). To participate in a distributed transaction, set the distributed transaction's object (ITransaction *) as an attribute value or set SQL_DTC_DONE.
- SQL_DTC_DONE: If the value is set, it will be executed as a local transaction after completing participation in distributed transaction.
ALTIBASE_APP_INFO Specify an identifier for an Altibase CLI application to obtain more detailed information on the user's session.
ALTIBASE_DATE_FORMAT Sets the date format.
Supports YYYY/MM/DD HH:MI:SS as the default.
ALTIBASE_CONN_ATTR_IPC_FILEPATH If ALTIBASE_HOME is different when server and client are connected by IPC in Unix environment, the socket path of Unix domain does not match. At this time, if ALTIBASE_HOME / trc / cm-ipc file is used, Unix domain communication is possible and information of shared memory can be obtained.
ALTIBASE_SOCK_RCVBUF_BLOCK_RATIO Sets the size of the socket receive buffer in 32K increments. If the value of this property is set to 2, the size of the socket receive buffer is 64K.
The default value is 0.
If the maximum socket receive buffer size among the TCP kernel parameters is set to less than the socket receive buffer size set by this property value, this property may be ignored or an error may be generated depending on the OS. (For Linux OS, it corresponds to 'net.core.rmem_max' TCP kernel parameter.)
ALTIBASE_MESSAGE_CALLBACK Registers a callback function to receive a message from the server. The user can handle the received message with a callback function. For details, refer to the sample below: <$ALTIBASE_HOME/sample/SQLCLI/demo_message.cpp>

Diagnosis#

SQLSTATE Description Comments
08S01 Communication channel error Communication channel failure before the function processing is completed between the Altibase CLI driver and the database
25000 Operation is not possible because local transaction is running Fails when attempting to join a distributed transaction with the SQL_ATTR_ENLIST_IN_DTC attribute in NON-AUTOCOMMIT mode
HY000 General error

In case of the statement attribute, SQLSetConnectAttr() can return any SQL state returned by SQLSetStmtAttr().

SQLAllocHandle

Example#

< Refer to: $ALTIBASE_HOME/sample/SQLCLI/demo_tran1.cpp >

if (SQLSetConnectAttr(dbc, SQL_ATTR_AUTOCOMMIT,
                    (void*)SQL_AUTOCOMMIT_OFF, 0) != SQL_SUCCESS)
{              
    execute_err(dbc, SQL_NULL_HSTMT, "Autocommit OFF");
    return SQL_ERROR;
}