SQL/MP Programming Manual for C
Host Variables
HP NonStop SQL/MP Programming Manual for C—429847-008
2-9
Variable-Length Character Data
 char prod_desc[6]; /* use for 5-character column */
 EXEC SQL END DECLARE SECTION;
 strcpy(prod_desc, "abc"); /* Copy 3 characters and */
 /* null terminator */
 ...
 /* Do not include space for null byte in the size */
 blank_pad(prod_desc, sizeof prod_desc - 1);
 EXEC SQL INSERT INTO =products VALUES (:prod_desc);
}
Variable-Length Character Data 
The VARCHAR data type represents one data element; however, the C compiler 
converts the type to a structure with two data items. The C compiler derives the group 
item name from the VARCHAR column name and the names of the subordinate data 
items, where:
len is a numeric data item that represents the length. 
val is a fixed-length character data item for the string, plus an extra byte for the 
null terminator, if the SQL pragma specifies the CHAR_AS_STRING option.
For example, if a column CUSTNAME is defined as VARCHAR(26), and the SQL 
pragma specifies the CHAR_AS_STRING option, INVOKE generates this structure: 
struct 
{
 short len;
 char val[27];
} custname;
You can refer to the individual data items or the structure name as host variables. 
If you explicitly declare a structure as a host variable for a VARCHAR column (rather 
than using INVOKE), declare the length as a short data type (and not an int). 
Structures 
You can refer to a structure name as a host variable only if the structure corresponds 
to a VARCHAR data type. For structures that do not correspond to a VARCHAR data 
type, the fields within the structure are the host variables. However, when you refer to 
an individual field name in the structure, you must include the structure name with the 
field name. For example, the structure employee_info contains the empid and 
empname fields: 
EXEC SQL BEGIN DECLARE SECTION;
struct employee
{
 long empid;
 char empname[21];
} employee_info;
EXEC SQL END DECLARE SECTION;










