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-21
Numeric Data
•
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;
printf("SQLCODE after insert - 3 is %d\n", SQLCODE);
EXEC SQL COMMIT WORK;
printf("\nSQLCODE after COMMIT WORK is %d\n\n", SQLCODE);
return 0;
Assigning Floating-Point Data Types
A column in an SQL/MX format table declared with a floating-point data type is stored
in IEEE floating-point format, and all computations on it are done assuming that. In
addition, all computations performed in MXCI, either on SQL/MX or SQL/MP tables,
use IEEE floating-point format.
A column in an SQL/MP format table declared with a floating-point data type is stored
in Tandem floating-point format, and all computations on it are done assuming that.
NonStop SQL/MX provides an option to store SQL/MP floating-point data in host
variables in IEEE floating-point format. The difference between IEEE and Tandem
floating-point format is seen in the storage, precision, and implementation for the
formats. Input and output via host variables can be treated as IEEE or Tandem floating-
point format.