GNADE User's Guide: GNADE, The GNat Ada Database Environment; Version 1.5.0; Document Revision $Revision: 1.42 $ | ||
---|---|---|
Prev | Chapter 10. Embedded SQL Syntax Specification | Next |
The GNADE ESQL translator supports implementation defined data types as e.g. VARCHAR in order to simplify the implementation of Ada 95 applications. The specifications of these types is done in the SQL_STANDARD.GNADE package.
<GNADE impl. specific types> ::= 'VARCHAR ( ' <max> ')', | 'VARBINARY ( ' <max> ')' ;
The type VARCHAR is used to handle strings with variable length. The descriminant in the VHARCHAR type specifies the maximal size of a string.
The application programmer may use the operations Is_Null and Length to figure out if the variable contains data and the length of the data.
An application example is shown below. Additional examples may found in the samples/esql directory.
Example 10-7. Using VARCHAR
with Ada.Strings; use Ada.Strings; with sql_standard; use sql_standard; with gnu.db.esql_Support; use gnu.db.esql_support; use gnu.db; procedure Test is val : String := "FIRSTNAME"; -- declare host and program variables EXEC SQL BEGIN DECLARE SECTION; ENAME : GNADE.VARCHAR(50); EMPNO : sql_standard.int; SQLCODE : sql_standard.sqlcode_type; -- for ANSI mode SQLSTATE : sql_standard.sqlstate_type; -- ANSI mode tt : GNADE.VARCHAR ( 50 ); EXEC SQL END DECLARE SECTION; SQL_ERROR : exception; SQL_WARNING : exception; begin EXEC SQL CONNECT $DBUSER IDENTIFIED BY $DBPASSWD TO $DBSOURCE ; To_VARCHAR( "Michael", tt ); EXEC SQL SELECT empno, name INTO :EMPNO, :ENAME FROM employees WHERE FIRSTNAME = :tt ; Put_Line( "empno : " & Integer'Image(Integer(empno)) ); Put_Line( "found name : " & To_String( ename ) ); end Test;