IBM® Informix® Client Software Development Kit, Version 4.10

The intoasc() function

The intoasc() function converts the field values of an interval variable to an ASCII string that conforms to the ANSI SQL standard.

Syntax

mint intoasc(invvalue, outbuf)
   intrvl_t *invvalue;
   char *outbuf;
invvalue
A pointer to an initialized interval variable to convert.
outbuf
A pointer to the buffer that receives the ANSI-standard INTERVAL string for the value in invvalue.

Usage

The intoasc() function converts the digits of the fields in the interval variable to their character equivalents and copies them to the outbuf character string with delimiters (hyphen, space, colon, or period) between them. You must initialize the interval variable in invvalue with the qualifier that you want the character string to have.

The character string does not include the qualifier or the parentheses that SQL statements use to delimit an INTERVAL literal. The outbuf string conforms to ANSI SQL standards. It includes one character for each delimiter (hyphen, space, colon, or period) plus fields with the following sizes.

Field
Field size
Leading field
As specified by precision
Fraction
As specified by precision
All other fields
Two digits
An interval value with the day(5) to fraction(5) qualifier produces the maximum length of output. The string equivalent contains 16 digits, 4 delimiters, and the null terminator, for a total of 21 bytes:
DDDDD HH:MM:SS.FFFFF

If you do not initialize the qualifier of the interval variable, the intoasc() function returns an unpredictable value, but this value does not exceed 21 bytes.

Return codes

0
The conversion was successful.
<0
The conversion failed.

Example

The demo directory contains this sample program in the file intoasc.ec.
/*
   * intoasc.ec *

   The following program illustrates the conversion of an interval (intvl_t)
   into an ASCII string.
*/

#include <stdio.h>

EXEC SQL include datetime;

main()
{
    mint x;
    char out_str[10];

    EXEC SQL BEGIN DECLARE SECTION;
      interval day(3) to day in1;
    EXEC SQL END DECLARE SECTION;

    printf("INTOASC Sample ESQL Program running.\n\n");

    printf("Interval (day(3) to day) string is '3'\n");
    if(x = incvasc("3", &in1))
      printf("Initial conversion failed with error: %d\n",x);
    else
      {
      /* Convert the internal format to ascii for displaying */
      intoasc(&in1, out_str);
      printf("\tInterval value after conversion  is '%s'\n", out_str);
      }

    printf("\nINTOASC Sample Program over.\n\n");
}

Output

INTOASC Sample ESQL Program running.

Interval (day(3) to day) string is '3'
Interval value afer conversion  is '   3'

INTOASC Sample Program over.


Examples exchange | Troubleshooting

To find the PDF, see Publications for the IBM Informix 12.10 family of products.
For the release notes, documentation notes, and/or machine notes, see the Release Notes page.