Decimal Data Types; Fixed-Point Data Types - HP NonStop SQL/MP Programming Manual

For c
Table of Contents

Advertisement

Host Variables

Decimal Data Types

Use the DECIMAL data type for ASCII numeric data. Because a decimal string is
actually a fixed-length character string that contains only ASCII digits, considerations
for fixed-length character strings also apply to decimal strings. Follow these guidelines
when you use character arrays as host variables for DECIMAL data:
Declare a decimal array one byte larger than the number of digits you expect to
store in the array.
Append a null terminator to an SQL/MP decimal string before you process it as a
C decimal string.
Right justify a C decimal string and pad the string on the left with ASCII zeros up to
the length of the corresponding SQL column before you insert the value into the
database.
HP C does not support direct manipulation of decimal strings. To perform C arithmetic
operations on SQL columns of DECIMAL data type, first convert the column to an
integral type using the dec_to_longlong routine.
HP C also provides the longlong_to_dec routine to convert type long long to type
decimal. Although the longlong_to_dec routine supports a variety of formats for
signed decimal strings, NonStop SQL/MP supports only the embedded leading signed
format. Therefore, always specify the embedded leading signed format when you
intend to pass the converted decimal string to NonStop SQL/MP.
For more information about C routines, see the C/C++ Programmer's Guide.

Fixed-Point Data Types

HP C does not have a data type that maps directly to a fixed-point number (that is, an
SQL numeric data type with scale). If you transfer fixed-point values 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/MP 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/MP stores the integral part of the value and generates a warning to indicate a
loss of data (the fractional part). To retain the fractional part, use the SETSCALE
function to scale the fixed-point value before transferring it to the host variable.
SETSCALE Function
The SETSCALE function directs NonStop SQL/MP to use a host variable in SQL
statements as if the host variable were declared with a specific scale. Use the
SETSCALE function for these operations:
To insert scaled values (for example, prices) into a database
HP NonStop SQL/MP Programming Manual for C—429847-008
2-11
Decimal Data Types

Advertisement

Table of Contents
loading

Table of Contents