| GNADE User's Guide: GNADE, The GNat Ada Database Environment; Version 1.2.0; Document Revision $Revision: 1.26 $ | ||
|---|---|---|
| Prev | Next | |
The GNU Embedded SQL Translator for Ada 95 reads a Ada 95 source file containing an Ada 95 package which contains embedded SQL Commands. A typical code fragment which is embedded into a normal Ada 95 source text is shown below:
Example 10-1. Example for Embedded SQL
EXEC SQL AT DB01x
SELECT LOCATION INTO :dep_location
FROM departments
WHERE DEPTNO = :depno ;
if SQLCODE not in SQL_STANDARD.NOT_FOUND then
Put_Line(
"Employee : " & Trim(To_String(Name),Right) & -- bug
" working in dep. " & INT'Image(depno) & --
" located at " & Trim(To_String(dep_location),Right) );
end if;
..............
In order to communicate to data bases, ESQL uses in each ESQL statement an optional data base identifier. This identifier is assigned by means of a connect statement to a data base as shown below. First of all is the connection identifier declared to be DB01.
........
EXEC SQL DECLARE DB01 DATABASE ;
.........
begin
EXEC SQL CONNECT "gnade"
IDENTIFIED BY "xxxxxxx"
BY DB01
TO "DEMO_DB" ;
end;
Later, during the initialization of the package, we connect as user
"gnade" with the password "xxxxxx" to the database "DEMO_DB". The
connection which will be used will be referred as DB01 in all ESQL
statements. The name DEMO_DB refers to the data source name in the
ODBC setup.