| GNADE User's Guide: GNADE, The GNat Ada Database Environment; Version 1.2.0; Document Revision $Revision: 1.26 $ | ||
|---|---|---|
| Prev | Chapter 11. Embedded SQL Syntax Specification | Next |
In order to connect to a data base, the data base identifier to be used has to be defined first. This identifier is a simple name which may be used in the AT clause of an embedded SQL statement and is declared by means of the "declare_db_clause". This clause will insert at the source where the clause is invoked a Ada statement declaring a connection object.
Syntax:
<connect_clause> ::=
CONNECT [ user ]
[ BY <Connection> ]
[ TO <db_name> ]
[ AS <name> ]
[ IDENTIFIED BY <password> ]
[ ON [COMMUNICATION|ATHORIZATION|OTHER] ERROR
[RAISE|GOTO|DO] <target> ]
<declare_db_clause> ::=
DECLARE <name> DATABASE
As shown in the example below, the declare_db_clause may be used
in the argument list of a procedure.
Example 11-3. Using DB connections as procedure arguments
procedure Print_Employee(
His_Number : Integer;
EXEC SQL DECLARE DB01x DATABASE ) is
---
...........
---
begin
empno := INT(His_Number);
EXEC SQL WHENEVER NOT FOUND DO Not_Found;
EXEC SQL AT DB01x
SELECT NAME, DEPTNO INTO :name, :depno
FROM employees
WHERE EMPNO = :empno ;
.....................
end Print_Employee;
The 'ON' clause is used to define the handling of errors which may occure during connection. Please note, that the execution of a procedure is straigth forward, which means after the procedure returns the execution continues after the connect statement!
Implementation Note: The data base connection variable inserted by this statement has the name GNADE_DB_<db_name> and is of the type ESQL_Support.CONNECTION_Handle. Such a name should never be used in the application code.