Entering content frame

 Generating Structure Definitions 

Use

You can use the INCLUDE DECLARE statement to generate a file <file_name> from a database table or database procedure. This file derives a corresponding structure definition from the structure of the database table. You can use this structure definition to declare host variables and the corresponding indicator variables.

A table has been defined as follows:

CREATE TABLE example (
  A FIXED (5),
  B FIXED (8),
  C FIXED (5, 2),
  D FLOAT (5),
  E CHAR (80))

The application program can then contain the following statements:

EXEC SQL BEGIN DECLARE SECTION;

EXEC SQL INCLUDE "example.h" TABLE example AS STRUCT IND;

struct example s, sa[10], *sp;

struct iexample indi;

EXEC SQL END DECLARE SECTION;

EXEC SQL SELECT * FROM example;

EXEC SQL FETCH INTO :s :indi;

EXEC SQL FETCH INTO :sa[4] :indi;

sp = &sa[9];

EXEC SQL FETCH INTO :sp :indi;

The include statement generates the following declarations:

struct example {short A;long B;float C,D;char E [81];};

and

struct iexample {short IA, IB, IC, ID, IE;};

 

Leaving content frame