SQL/MX 3.1 Programming Manual for C and COBOL (H06.23+, J06.12+)

Host Variables in C/C++ Programs
HP NonStop SQL/MX Release 3.1 Programming Manual for C and COBOL663854-001
3-25
Date-Time and Interval Data
TIMESTAMP) host variable. For the required number of digits for DATE, TIME, or
TIMESTAMP values, see Table 3-3 on page 3-9.
If your C program performs string operations on the date-time host variable, you must
append a null terminator to the output string before processing it because the date-time
data types are internally processed as C character strings.
Table 3-7 lists the lengths of the target arrays for TIME and TIMESTAMP values, which
depend on the precision (the number of digits in the fractional seconds).
The TIME default precision is 0 (zero), and the TIMESTAMP default precision is 6.
Example
If a database has a BILLINGS table that consists of the CUSTNUM and
BILLING_DATE columns, this example selects the date-time value:
EXEC SQL BEGIN DECLARE SECTION;
struct billing_rec {
unsigned short hv_custnum;
DATE hv_billing_date;
...
} bill;
...
EXEC SQL END DECLARE SECTION;
...
EXEC SQL SELECT custnum, billing_date
INTO :bill.hv_custnum, :bill.hv_billing_date
FROM billings
WHERE custnum = :hv_this_customer;
... bill.hv_billing_date[10]='\0';
Inserting or Updating Standard Date-Time Values
To insert or update standard date-time values (DATE, TIME, or TIMESTAMP, or the
SQL/MP DATETIME equivalents) in the database, format the date-time values in the
desired display format for a date, time, or timestamp. Within an INSERT or UPDATE
statement, use the DATE, TIME, or TIMESTAMP data type.
Table 3-7. Lengths of C Target Arrays for TIME and TIMESTAMP
TIME Precision Length TIMESTAMP Precision Length
TIME 9 TIMESTAMP 27
TIME(0) 9 TIMESTAMP(0) 20
TIME(1) 11 TIMESTAMP(1) 22
TIME(2) 12 TIMESTAMP(2) 23
TIME(3) 13 TIMESTAMP(3) 24
TIME(4) 14 TIMESTAMP(4) 25
TIME(5) 15 TIMESTAMP(5) 26
TIME(6) 16 TIMESTAMP(6) 27
C