2. Embedded SQL for C : C Variables and Data Types : Variable and Type Declarations : Embedded SQL/C Declarations Example
 
Share this page                  
Embedded SQL/C Declarations Example
The following example demonstrates some simple embedded SQL/C declarations:
exec sql include sqlca; /* include error handling */
exec sql begin declare section;
 # define max_persons 1000
  typedef struct datatypes_/* Structure of all types */
      {
            char d_byte;
            short d_word;
            long d_long;
            float d_single;
            double d_double;
            char *d_string;
      } datatypes;
  datatypes d_rec;
  char *dbname = "personnel";
      char *formname, *tablename, *columnname;
  varchar struct {
            short len;
            char binary_data[512];
      } binary_chars;
  enum color {RED, WHITE, BLUE} col;
  unsigned int empid;
      short int vac_balance;
  struct person_ /* Structure with a union */
      {
            char age;
            long flags;
            union
            {
                  char full_name[30];
                  struct {
                         char firstname[12], lastname[18];
                   } name_parts;
             } person_name;
      } person, *newperson, person_store[MAX_PERSONS];
exec sql include 'employee.dcl'; /* From DCLGEN */
Windows:
extern int *empform, *deptform; /* Compiled forms */
exec sql end declare section;
UNIX:
extern int *empform, *deptform; /* Compiled forms */
exec sql end declare section;
VMS:
globalref int *empform, *deptform; /* Compiled forms */
exec sql end declare section;