Hitachi

Hitachi Advanced Database Application Development Guide


19.5.3 a_rdb_CNV_charDECIMAL() (convert to DECIMAL-type data)

Organization of this subsection

(1) Function

This CLI function converts character string data in C or C++ to SQL DECIMAL-type data. The following figure shows an example of conversion from character string data to DECIMAL-type data.

Figure 19‒3: Example of conversion from character string data to DECIMAL-type data

[Figure]

Important

The character string data before conversion must be in the following format:

'[[Figure]...Δ][+|-][aa....aa][.][bb....bb]'

[[Figure]...Δ]: Zero or more spaces

[+|-]: Plus or minus sign (if the sign is omitted, a plus sign is assumed)

[aa....aa]: Integer part

[.]: Decimal point (if there is no fractional part, the decimal point can be omitted)

[bb....bb]: Fractional part

Please note the following:

  • You can specify only an integer part [aa....aa]; if you specify a fractional part, [bb....bb], you must also specify the decimal point [.].

  • The length of the integer part [aa....aa] and the fractional part [bb....bb] must not exceed 38 places.

  • If the decimal point (period) is omitted when you specify an integer part only, a decimal point is assumed at the end of the data obtained after conversion.

(2) Format

#include <adbcnv.h>
 
signed short a_rdb_CNV_charDECIMAL
(
  char                 *char_Data,                /* In  */
  unsigned short        char_Length,              /* In  */
  unsigned short        DECIMAL_Precision,        /* In  */
  unsigned short        DECIMAL_Scale,            /* In  */
  unsigned char        *DECIMAL_Data,             /* Out */
  unsigned short        BufferLength,             /* In  */
  void                 *Option                    /* In  */
)

(3) Arguments

char_Data

Specifies the start address of the area where the character string data before conversion (character string data in C or C++) is stored.

char_Length

Specifies the length (in bytes) of the character string data before conversion. The permitted value range is from1 to 41.

DECIMAL_Precision

Specifies the precision of the DECIMAL-type data (total number of digits) after conversion. The permitted value range is from 1 to 38.

Specify the same precision as for the dynamic parameter that is to be associated.

DECIMAL_Scale

Specifies the scaling of the DECIMAL-type data (number of decimal places) after conversion. The permitted value range is from 0 to 38.

Specify the same scaling as for the dynamic parameter that is to be associated.

DECIMAL_Data

Specifies the start address of the area where the DECIMAL-type data after conversion is to be stored.

BufferLength

Specifies the length (in bytes) of the area where the DECIMAL-type data after conversion is to be stored. Specify the following value:

Table 19‒6: Value of BufferLength

No.

Value of DECIMAL_Precision

Value of BufferLength

1

1 ≤ DECIMAL_Precision ≤ 4

2

2

5 ≤ DECIMAL_Precision ≤ 8

4

3

9 ≤ DECIMAL_Precision ≤ 16

8

4

17 ≤ DECIMAL_Precision ≤ 38

16

Option

Specifies NULL.

(4) Return value

  1. If a_rdb_CNV_charDECIMAL() terminates normally, a_rdb_RC_CNV_SUCCESS is returned.

  2. If an error occurs, the error code is returned as the return value. For details about the error code, see 19.8 Return values of the CLI functions.

(5) Notes

  1. You must ensure that there is no overlap between the area for storing the data before conversion (char_Data) and the area for storing the data after conversion (DECIMAL_Data).

  2. If the data before conversion is equivalent to "-0.", "+0." consisting of the same number of characters is assumed. For example, if the data to be converted is "-0.0", "+0.0" is assumed; if the data before conversion is "-0.0000", "+0.0000" is assumed.

  3. The character string data before conversion is converted to DECIMAL-type data, and then stored from the beginning of the storage area. If the integer part cannot be stored, an error results. If the fractional part cannot be stored, the excess places are discarded.

  4. You can specify character string data in which a zero has been added to the integer part only if the precision and scaling match. In this case, for DECIMAL_Precision, specify the number of digits without the zero in the integer part.