Previous Topic

Next Topic

Using c-treeSQL in a Host Language

The c-treeSQL data language is a non-procedural language that uses SQL statements for defining, manipulating, and controlling data in a relational database.

The ESQL tool gives you the ability to embed c-treeSQL statements in a host language program. Embedding c-treeSQL statements in a procedural language program lets you take advantage of the flow-control and other features of the host language as well as the standardized query capabilities of c-treeSQL.

ESQL supports C language host programs. It provides a precompiler, esqlc, that translates each embedded SQL statements in a host program to the equivalent C calls to functions in the c-treeSQL application programming interface (API).

The following example shows a brief C code fragment with embedded SQL statements.

Note that all embedded SQL statements start with the prefix EXEC SQL and end with a semicolon character ( ; ). For more information on EXEC SQL statements, see “EXEC SQL”.

Note also that, in addition to standard SQL statements, you use EXEC SQL to embed other ESQL constructs in host programs, such as BEGIN DECLARE … END DECLARE blocks.

Example ESQL Code


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 code to get values for host variables */
  order_no_v = 1001 ;
  strcpy (order_date_v, "02/02/1993") ;
  strcpy (product_v, "COG") ;
  qty_v = 10000 ;

printf ("Registering the order…") ;

EXEC SQL
  INSERT INTO orders
    (order_no, order_date, product, qty)
  VALUES
    (:order_no_v, :order_date_v, :product_v, :qty_v) ;