Hitachi

Hitachi Advanced Database Application Development Guide


18.2.1 Connecting to and disconnecting from the HADB server

This subsection explains the procedure for using CLI functions to connect to and disconnect from the HADB server.

The following figure shows the procedure from connection through disconnection from the HADB server.

Figure 18‒4: Procedure from connection through disconnection from the HADB server

[Figure]

#

For details about using SQL statements to manipulate data, see 18.2.2 Referencing data and its subsections.

Organization of this subsection

(1) Connecting to the HADB server

You use the following CLI functions to connect to the HADB server:

(a) Allocating a connection handle

Before you establish a connection, you must allocate a connection handle. You use a_rdb_SQLAllocConnect() to allocate a connection handle. When a connection handle has been allocated successfully, the value a_rdb_RC_SQL_SUCCESS is returned. The following shows an example of calling a_rdb_SQLAllocConnect().

Example of calling a_rdb_SQLAllocConnect()
signed short rtnc ;                 /* Return value */
void  *hCnct ;                      /* Connection handle address */
 
/* Allocate a connection handle */
rtnc = a_rdb_SQLAllocConnect(&hCnct,
                        "/hadb/client.def",   /* Client definition file path */
                        NULL) ;

You can use a different client definition for each connection by specifying the absolute path of the appropriate client definition file in the second argument of a_rdb_SQLAllocConnect(). For details about a client definition, see 4.4 Creating a client definition.

For details about a_rdb_SQLAllocConnect(), see 19.2.1 a_rdb_SQLAllocConnect() (allocate a connection handle).

(b) Establishing a connection

You use a_rdb_SQLConnect() to establish a connection. When a connection has been established, the value a_rdb_RC_SQL_SUCCESS is returned.

The following shows an example of calling a_rdb_SQLConnect().

Example of calling a_rdb_SQLConnect()
a_rdb_SQLResultInfo_t  rsltInfo ;          /* SQL results information */
 
/* Establish a connection */
rtnc = a_rdb_SQLConnect(hCnct,             /* Connection handle */
                      "ADBUSER01",         /* Authorization identifier */
                      "password01",        /* Password */
                      &rsltInfo,
                      NULL) ;

You can acquire SQL results information for each CLI function call by specifying the corresponding address of the SQL results information in the fourth argument of a_rdb_SQLConnect(). For details about SQL results information, see 19.7.6 a_rdb_SQLResultInfo_t structure (SQL results information).

For details about a_rdb_SQLConnect(), see 19.2.2 a_rdb_SQLConnect() (establish a connection).

(2) Disconnecting from the HADB server

You use the following CLI functions to disconnect from the HADB server:

(a) Closing the connection

You use a_rdb_SQLDisconnect() to close the connection. The following shows an example of calling a_rdb_SQLDisconnect().

Example of calling a_rdb_SQLDisconnect()
/* Close the connection */
rtnc = a_rdb_SQLDisconnect(hCnct, NULL) ;

For details about a_rdb_SQLDisconnect(), see 19.2.4 a_rdb_SQLDisconnect() (close a connection).

(b) Releasing the connection handle

After you have closed the connection, you must release the connection handle. You use a_rdb_SQLFreeConnect() to release a connection handle. The following shows an example of calling a_rdb_SQLFreeConnect().

Example of calling a_rdb_SQLFreeConnect()
/* Release the connection handle  */
rtnc = a_rdb_SQLFreeConnect(hCnct, NULL) ;

For details about a_rdb_SQLFreeConnect(), see 19.2.5 a_rdb_SQLFreeConnect() (release a connection handle).