Convert a locale-specific string
The HCL Informix® GLS conversion
functions scan the incoming locale-specific string to create a corresponding
internal representation, as shown in the following table.
Conversion function | Unconverted form | Converted form: ESQL/C data type | Converted form: DataBlade API data type |
---|---|---|---|
ifx_gl_convert_number() | Number string | decimal (dec_t) | mi_decimal |
ifx_gl_convert_money() | Money string | decimal (dec_t) | mi_decimal |
ifx_gl_convert_date() | Date string | date (long int) | mi_date |
ifx_gl_convert_datetime() | Date/time string | datetime (dtime_t) | mi_datetime |
The formatting directives in the format string tell the conversion functions what conversions to perform on the locale-specific string. To process a formatting directive, a conversion function consults the appropriate category in the current locale to obtain any locale-specific formats and then converts the resulting value to an internal representation that can be stored in a database.
For example, if the current locale is the default locale, the following DataBlade
API call
to the ifx_gl_convert_number() function converts
the number string "1,450" to its hexadecimal equivalent
in an mi_decimal value:
mi_decimal num_val;
...
if ( ifx_gl_convert_number(&num_val, "1,450","%0x") != 0 )
/* handle error */
In the current locale, the thousands separator is defined as the comma (,) symbol. Therefore, the ifx_gl_convert_number() function must correctly interpret the comma in the number string so that it can convert this string to the hexadecimal equivalent of the value 1450 and store the result in the mi_decimal value, num_val.
If the
current locale is French (fr_fr), the thousands separator is
a space. Therefore, the following call to ifx_gl_convert_number() must
interpret a space as the thousands separator to convert the French
number string ("1 450") successfully to its mi_decimal equivalent:
mi_decimal *num_val;
...
if ( ifx_gl_convert_number(num_val, "1 450","%0x") != 0 )
/* handle error */