Scalable Database Server, HiRDB Version 8 UAP Development Guide

[Contents][Index][Back][Next]

11.2.2 Using the default SQL connection

This section explains use of the default SQL connection as the current SQL connection for accessing a remote database.

When the default SQL connection is used as the current SQL connection, it is possible to access the databases of all distributed RD-nodes that can be connected to the default RD-node. To do this, it is necessary to use one of the following methods to notify the default RD-node's HiRDB of the distributed RD-node where the table and procedure to be accessed are located:

  1. By qualifying the table name with the RD-node name
  2. By using a table alias
  3. By qualifying the procedure name with the RD-node name

Methods (a) and (c) can also be used when a table or procedure located at the default RD-node is to be accessed. In such a case, the name is qualified with the RD-node name of the default RD-node. Tables or procedures whose names are not modified by an RD-node name are processed under the assumption that they are located at the current RD-node.

Use of the default SQL connection also enables access to the database of a distributed RD-node. However, the following restrictions apply:

Organization of this subsection
(1) Qualifying the table name with the RD-node name
(2) Using a table alias
(3) Qualifying the procedure name with the RD-node name
(4) Access using an authorization identifier that is different from the default SQL connection

(1) Qualifying the table name with the RD-node name

The following format is used to qualify the table name with the RD-node name:

RD-node-name.authorization-identifier.table-identifier

RD-node-name
Specifies the name of the RD-node where the table is located.

authorization-identifier.table-identifier
Specifies the authorization identifier and table identifier defined at the RD-node where the table is located.

Specification example
  • Retrieve the table named MANAGER.ORDERS at the RD-node named RDNODE10:
SELECT * FROM RDNODE10.MANAGER.ORDERS

(2) Using a table alias

The following format is used to specify the table at a distributed RD-node using a table alias. Note that a table alias is not supported if either the distributed server or the distributed client is Solaris.

[authorization-identifier.]table-alias

[authorization-identifier.]table-alias
Specifies the name defined in CREATE ALIAS. Note that the name specified here may not match the authorization identifier or the table identifier defined at the RD-node where the table is located.

Specification example
  • Assign the alias MANAGER.ORDERS, which is the same as the name defined at the RD-node where the table is located, to the table named MANAGER.ORDERS at the distributed RD-node named RDNODE10, and retrieve the table using this defined alias:
1. Using CREATE ALIAS to define an alias
CREATE ALIAS MANAGER.ORDERS FOR RDNODE10.MANAGER.ORDERS
2. Retrieval using the alias defined above
SELECT * FROM MANAGER.ORDERS

(3) Qualifying the procedure name with the RD-node name

The following format is used to qualify the procedure name with the RD-node name:

RD-node-name.authorization-identifier.routine-identifier

RD-node-name
Specifies the name of the RD-node where the procedure is located.

authorization-identifier.routine-identifier
Specifies the authorization identifier and routine identifier defined at the RD-node where the procedure is located.

Specification example
  • Retrieve the procedure named MANAGER.PROC10 at the RD-node named RDNODE10:
CALL RDNODE10.MANAGER.PROC10 (arguments)

(4) Access using an authorization identifier that is different from the default SQL connection

Even when the default SQL connection is used, an SQL connection to a distributed RD-node is required for accessing a remote database. If the UAP issues an SQL for accessing a remote database without creating an SQL connection, the HiRDB at the default RD-node generates automatically an SQL connection to the distributed RD-node.

However, because the SQL connection generated automatically by the HiRDB contains the same authorization identifier as the default SQL connection, the remote database cannot be accessed if that authorization identifier does not have the required privilege at the distributed RD-node. In such a case, it is possible to create an SQL connection that contains an authorization identifier that has the required privilege at the distributed RD-node in advance and then to use that SQL connection.

Usage example
In the example shown below, a CONNECT statement with RD-node specification is used to create an SQL connection that contains an authorization identifier that has the required privilege at the distributed RD-node. Because the SQL connection to the distributed RD-node becomes the current SQL connection when the CONNECT statement with RD-node specification is executed, the SET CONNECTION statement is used first to revert the current SQL connection to the default SQL connection, and then an SQL for accessing the remote database is issued.
CONNECT TO RDNODE10 USER:USER2 USING :PSWD2SET CONNECTION DEFAULTSELECT SQUANTITY INTO :QUANTITY FROM  RDNODE10.MANAGER.STOCK WHERE PCODE='302S'