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 COBOL—523627-004
3-20
Numeric Data
•
Within an INSERT or UPDATE statement, use the SQL/MX CAST function to
convert the character data to the desired SQL data type. The character set string
can be associated with either ISO88591 or UCS2 character set.
Assigning Numeric Data to Corresponding Data Types
You can perform C arithmetic operations on SQL columns of NUMERIC, PICTURE 9’s,
or DECIMAL data type. To do so, assign the data to host variables with the same data
type as the database data type (that is, NUMERIC, PICTURE 9’s, or DECIMAL) as
shown in Table 3-1 on page 3-8.
Table 3-5 lists the extended SQL C data types NUMERIC and PICTURE 9’s COMP.
Use NUMERIC or PICTURE 9’s COMP host variables within your C program as
shown.
Table 3-6 also lists the extended SQL C data types DECIMAL and PICTURE 9’s
DISPLAY. Use DECIMAL or PICTURE 9’s DISPLAY host variables within your C
program as shown in Table 3-6.
Assigning Fixed-Point Data Types
If you assign fixed-point values, an SQL NUMERIC data type with scale, to integral or
floating-point host variables, consider these guidelines:
•
When you transfer a fixed-point value to a host variable of floating-point data type,
NonStop SQL/MX converts the fixed-point value to a floating-point value and
generates a warning to indicate a loss of precision.
•
When you transfer a fixed-point value into an integer host variable, NonStop
SQL/MX stores the integral part of the value and generates a warning to indicate a
loss of data (the fractional part). Use this assignment only when you intend to
truncate the fractional part.
Table 3-5. Host Variable Usage for NUMERIC or PICTURE 9’s COMP Data
C Program Usage NUMERIC or PICTURE 9’s COMP Data
short The length l (the precision) is 1 through 4 digits.
long The length l (the precision) is 5 through 9 digits.
long long The length l (the precision) is 10 through 18 digits.
Table 3-6. Host Variable Usage for DECIMAL or PICTURE 9’s DISPLAY Data
C Program Usage DECIMAL or PICTURE 9’s DISPLAY Data
char[l + 2] The length l is the precision of the numeric data. Two extra
characters are allocated by the preprocessor: the first character
to store the sign (+, –, or blank) and the last character to store
the null terminator for the character string.