C structures as host variables

supports the declaration of a C structure (struct) as a host variable. You can use the components of the structure within statements.

The following definition of the cust_rec variable serves as a host variable for the first three columns of the customer table in the stores7 database:
EXEC SQL BEGIN DECLARE SECTION;
   struct customer_t
      {
      int   c_no;
      char   fname[32];
      char   lname[32];
      } cust_rec;
EXEC SQL END DECLARE SECTION;
The following INSERT statement specifies the components of the cust_rec host variable in its VALUES clause:
EXEC SQL insert into customer (customer_num, fname, lname)
   values (:cust_rec.c_no, :cust_rec.fname,
   :cust_rec.lname);

If an SQL statement requires a single host variable, you must use the structure component name to specify the host variable. HCL OneDB™ requires structure component names in the SET clause of an UPDATE statement.

In SQL statements that allow a list of host variables, you can specify the name of the C structure and expands the name of the structure variable to each of its component elements. You can use this syntax with SQL statements such as the FETCH statement with an INTO clause or the INSERT statement with a VALUES clause.

The following INSERT statement specifies the entire cust_rec structure in its VALUES clause:
EXEC SQL insert into customer (customer_num, fname, lname) 
   values (:cust_rec);

This insert performs the same task as the insert that specifies the individual component names of the cust_rec structure.