Progress
Embedded SQL-92
Guide and Reference


Embedding SQL-92 Statements in a C Language Program

SQL is a non-procedural language that uses statements to define, manipulate, and control data in a relational database. The Progress SQL-92 application development environment allows development of applications using the Embedded SQL tool. ESQL allows you to embed SQL-92 statements in the widely used C programming language. In this context, the C Language is referred to as the host language. Embedding SQL statements in a host language allows for development of applications that are more powerful and flexible than applications developed in either the host language or SQL alone. The Progress embedded SQL-92 interface in C is referred to as ESQLC.

C Language compilers do not recognize SQL statements and ESQL application programs containing SQL statements. It is necessary to translate these statements to the equivalent C Language code to build the program executable. The ESQL precompiler performs this translation.

To facilitate recognition of the statements the ESQL precompiler is to process, you begin the statements with the prefix EXEC SQL. These prefixed statements are referred to as ESQL constructs. The ESQL constructs are outlined in following sections.

NOTE: See "ESQL-92 Program Structure," for a complete description of each ESQL construct.

EXAMPLE

The following code fragment is an overview of how SQL statements can be embedded in C:

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 code to determine values for host variables. 
** Typically you retrieve values through a user interface.
*/
order_no_v = 1001 ;     
strcpy (order_date_v, "02/02/1999") ;   
strcpy (product_v, "COG") ;    
qty_v = 10000 ;
printf ("Registering the order\n") ;  
 
EXEC SQL
     INSERT INTO orders    
          (order_no, order_date, product, qty)   
     VALUES     
          (:order_no_v, :order_date_v, :product_v, :qty_v) ; 


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