SQL/MX Programming Manual for C and COBOL (G06.24+, H06.03+)

Host Variables in C/C++ Programs
HP NonStop SQL/MX Programming Manual for C and COBOL523627-004
3-28
Host Variables in C Structures
Example
A database contains a BILLINGS table consisting of the CUSTNUM, START_DATE,
BILLING_DATE, and TIME_BEFORE_PMT columns. This example updates date-time
and interval values:
EXEC SQL BEGIN DECLARE SECTION;
struct billing_rec {
unsigned short hv_custnum;
DATE hv_start_date;
DATE hv_billing_date;
INTERVAL DAY(3) hv_time_before_pmt;
} bill;
...
EXEC SQL END DECLARE SECTION;
...
bill.hv_start_date[10]='\0'
bill.hv_billing_date[10]='\0';
/* Blank pad if the interval data is less than 3 digits. */
...
strcpy(bill.hv_time_before_pmt," 111");
EXEC SQL UPDATE billings
SET billing_date = :bill.hv_billing_date,
time_before_pmt = :bill.hv_time_before_pmt
WHERE custnum = :hv_this_customer;
...
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-15.
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 {
unsigned short empnum;
char empname[21];
} employee_info;
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:
EXEC SQL SELECT empnum, empname
INTO :employee_info.empnum, :employee_info.empname
... ;
C
C