Progress
Embedded SQL-92
Guide and Reference


Using Host Variables

You must declare host variables in the DECLARE SECTION before you can use them in an ESQL executable statement. The data types used to declare host variables generally must be the same types as database types. For example, to declare a host variable of C Language type SHORT, the precompiler allows you to DECLARE the variable as database type SMALLINT.

This is the general format for declaring host variables in the DECLARE SECTION:

SYNTAX
EXEC SQL BEGIN DECLARE SECTION ;
 
    data_type   host_variable_name1 ;
    [ data_type   host_variable_name2 ; ]
 
EXEC SQL END DECLARE SECTION ; 

host variable

SYNTAX
EXEC SQL
    :host_variable_name 

NOTE: When you use a host variable in an ESQL executable statement, you must prepend a colon ( : ) to the variable.

EXAMPLE

The following code fragment shows the use of host variables in an embedded SQL program:

EXEC SQL BEGIN DECLARE SECTION ;
     long order_no_v ;
     char order_date_v[10] ;
     char product_v[5] ;
     long qty_v ;
EXEC SQL END DECLARE SECTION ;
   .
   .
   .
/*
** C Language processing code here, to determine values for host variables
*/
   .
   .
   .
/*
** ESQL executable statement.
** INSERT a row with 4 column values into the orders table.
*/
EXEC SQL
     INSERT INTO orders (order_no, order_date, product, qty)
     VALUES (:order_no_v, :order_date_v, :product_v, :qty_v) ; 

The following list provides a summary of how and when to use host variables:


Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095