SQL/MX 3.2 Programming Manual for C and COBOL (H06.25+, J06.14+)
Host Variables in C/C++ Programs
HP NonStop SQL/MX Release 3.2 Programming Manual for C and COBOL—663854-002
3-28
Numeric Data
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,
the application must use binary_64_s=1237000. The scale is implicit and must
be handled in the application.
int main()
{
Exec sql set catalog 'ework';
Exec sql set schema 'ework';
SQLCODE = -1;
memset(SQLSTATE, 32, 6);
strncpy(insert_buf, " ", sizeof(insert_buf));
strcpy(insert_buf, "INSERT INTO tb32 (binary_64_s) VALUES
(cast(? as numeric(18, 3)));");
EXEC SQL PREPARE ins FROM :insert_buf;
printf("SQLCODE after PREPARE ins is %d\n", SQLCODE);
binary_64_s = 1273;
ia = 0;
EXEC SQL EXECUTE ins USING :binary_64_s indicator :ia;
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.










