Hitachi

Hitachi Advanced Database Application Development Guide


19.5.9 a_rdb_CNV_DECIMALchar() (convert DECIMAL-type data)

Organization of this subsection

(1) Function

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

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

[Figure]

Explanation:
  • This example converts DECIMAL-type data to a character string representing an unsigned decimal literal.

  • If the same values are specified for DECIMAL_Precision and DECIMAL_Scale, a zero is added before the decimal point, and then the data is converted to a character string.

  • If the value of DECIMAL_Scale is zero, the decimal point is not added.

  • If the data is a negative number, a minus sign (-) is added at the beginning.

  • The value is padded with trailing null characters (0x00), and then the data is stored right-aligned in the storage area.

  • If the stored character string is shorter than the value of BufferLength, the remaining area is padded with space characters.

(2) Format

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

(3) Arguments

DECIMAL_Data

Specifies the start address of the area where the DECIMAL-type data before conversion is stored.

DECIMAL_Precision

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

Specify the same precision as for the data type of the fetched column's value.

DECIMAL_Scale

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

Specify the same scaling as for the data type of the fetched column's value.

char_Data

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

BufferLength

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

value of DECIMAL_Precision + 4

Option

Specifies NULL.

(4) Return value

  1. If a_rdb_CNV_DECIMALchar() 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

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