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-40
Character Set Examples
Character Set Examples
This set of examples shows methods for selecting, fetching, and inserting data using
different character sets. The examples are based on these tables:
CREATE TABLE STAFF_UC
(EMPNUM CHAR(3) character set ucs2 NOT NULL UNIQUE,
EMPNAME NCHAR VARYING(20),
GRADE DECIMAL(4),
CITY VARCHAR(15) character set ucs2);
CREATE TABLE PROJ
(PNUM CHAR(3) NOT NULL,
PNAME VARCHAR(20),
PTYPE CHAR(7),
BUDGET DECIMAL(9),
CITY VARCHAR(15),
/* Initialize the host variables in the WHERE clause. */
...
EXEC SQL
SELECT ordernum, partnum, unit_price, qty_ordered
INTO :odetail_rec.ordernum,
:odetail_rec.partnum,
:odetail_rec.unit_price
INDICATOR :odetail_rec.unit_price_i,
:odetail_rec.qty_ordered
INDICATOR :odetail_rec.qty_ordered_i
FROM sales.odetail
WHERE ordernum = :in_ordernum AND partnum = :in_partnum;
...
if (odetail_rec.unit_price_i < 0 ||
odetail_rec.qty_ordered_i < 0)
handle_null();
else
display_result();
return 0;
} /* end main */
void handle_null()
{
...
} /* end handle_null */
void display_result()
{
printf("Order number: %6d\n", odetail_rec.ordernum);
printf("Part number: %4d\n", odetail_rec.partnum);
printf("Unit price: %10.2lf\n", odetail_rec.unit_price/100.);
printf("Quantity ordered: %5d\n", odetail_rec.qty_ordered);
} /* end display_result */
Example 3-3. C INVOKE (page 2 of 2)