ALLBASE/SQL Reference Manual (36216-90216)

102 Chapter2
Using ALLBASE/SQL
Using Multiple Connections and Transactions with Timeouts
attempted. From a menu, the user chooses to view account information and specifies an
account number. Before giving this information, the application logs the fact that the user
is requesting it. The following pseudocode example illustrates how you might code two
simultaneous transactions, each one accessing BankDBE using host variables:
1. Put multi-transaction mode in effect.
SET MULTITRANSACTION ON
DECLARE BankCursor
CURSOR FOR
SELECT TransactionType,
DollarAmount,
BankNumber
FROM Accounts
WHERE AccountNumber = :AccountNumber
2. Connect two times to BankDBE. Be sure to specify an appropriate timeout value for
each connection.
CONNECT TO 'BankDBE' AS 'Bank2'
SET USER TIMEOUT 30 SECONDS
CONNECT TO 'BankDBE' AS 'Bank1'
SET USER TIMEOUT 30 SECONDS
The user enters an account number.
3. Begin a transaction for the Bank1 connection.
BEGIN WORK RC
.
.
.
4. Execute the following security audit subroutine:
Set the current connection to Bank2.
SET CONNECTION 'Bank2'
Begin a second transaction for BankDBE.
BEGIN WORK RC
A security audit trail record is written whether or not the query in the first transaction
completes.
INSERT INTO BankSecurityAudit
VALUES (:UserID, :AccountNumber, CURRENT_DATETIME)
Test the sqlcode field of the sqlca. If it equals -2825, a timeout has occurred, and the
transaction was rolled back. Take appropriate action.
End the transaction.
COMMIT WORK