SQL/MX 3.2.1 Programming Manual for C and COBOL (H06.26+, J06.15+)
Host Variables in C/C++ Programs
HP NonStop SQL/MX Release 3.2.1 Programming Manual for C and COBOL—663854-005
3-40
Host Variables in C Structures
If the interval string length is larger than the number of digits in the interval value, you
must blank pad up to the null terminator. See Inserting or Updating Fixed-Length
Character Data on page 3-18.
Host Variables in C Structures
When you refer to a single field name in a structure, you must include the structure
name with the field name.
Example
This example uses a structure named employee_info, containing the empnum and
empname fields:
EXEC SQL BEGIN DECLARE SECTION;
struct employee { /* structure definition */
unsigned short empnum;
char empname[21];
};
struct employee emp_input; /* directly allocated structure */
struct employee * emp_output; /* structure pointer */
EXEC SQL END DECLARE SECTION;
To use a field as a host variable in an SQL statement, refer to the field by using the
structure names:
emp_output = malloc(sizeof(employee));
emp_input.empnum = 100;
EXEC SQL SELECT empname
-- reference hostvar through struct pointer
INTO :emp_output->empname
FROM CAT.SCH.EMPLOYEE
-- reference hostvar as struct field
WHERE empnum = :emp_input.empnum;
Host Variables as Data Members of a C++ Class
You can include an SQL Declare Section within a class definition to use a data
member of a class as a host variable.
Example
This example uses a class named jobsql, containing the declarations of the
memhv_jobcode and memhv_jobdesc host variables. These host variables are
referenced in the member function putjob defined in the class:
class jobsql {
// Class member host variables
EXEC SQL BEGIN DECLARE SECTION;
unsigned NUMERIC (4) memhv_jobcode;
VARCHAR memhv_jobdesc[19];
EXEC SQL END DECLARE SECTION;
C
C++










