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-21
Numeric Data
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.
When you declare a fixed-point value (NUMERIC), NonStop SQL/MX translates
the value to 'long long' in the C language. The 'long long' data type has no
scale. In the next example, when the value is assigned using host variable
binary_64_s, the host variable value is 1273. The decimal point is implicit, so the
actual value interpreted by SQL is 1.273. To place a value of 1273 into the table,
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.