The incvasc() function
The incvasc() function converts a string that conforms to the ANSI SQL standard for an INTERVAL value to an interval value.
Syntax
mint incvasc(inbuf, invvalue)
char *inbuf;
intrvl_t *invvalue;
- inbuf
- A pointer to a buffer that contains an ANSI-standard INTERVAL string.
- invvalue
- A pointer to an initialized interval variable.
Usage
You must initialize the interval variable in invvalue with the qualifier that you want this variable to have.
The character string in inbuf can have leading and trailing spaces. However, from the first significant digit to the last, inbuf can only contain characters that are digits and delimiters that are appropriate to the qualifier fields of the interval variable.
If the character string is an empty string, the incvasc() function sets the value in invvalue to null. If the character string is acceptable, the function sets the value in the interval variable and returns zero. Otherwise, the function sets the value in the interval value to null.
Return codes
- 0
- The conversion was successful.
- -1260
- It is not possible to convert between the specified types.
- -1261
- Too many digits in the first field of datetime or interval.
- -1262
- Non-numeric character in datetime or interval.
- -1263
- A field in a datetime or interval value is out of range or incorrect.
- -1264
- Extra characters at the end of a datetime or interval value.
- -1265
- Overflow occurred on a datetime or interval operation.
- -1266
- A datetime or interval value is incompatible with the operation.
- -1267
- The result of a datetime computation is out of range.
- -1268
- A parameter contains an invalid datetime or interval qualifier.
Example
/*
* incvasc.ec *
The following program converts ASCII strings into interval (intvl_t)
structure. It also illustrates error conditions involving invalid
qualifiers for interval values.
*/
#include <stdio.h>
EXEC SQL include datetime;
main()
{
mint x;
EXEC SQL BEGIN DECLARE SECTION;
interval day to second in1;
EXEC SQL END DECLARE SECTION;
printf("INCVASC Sample ESQL Program running.\n\n");
printf("Interval string #1 = 20 3:10:35\n");
if(x = incvasc("20 3:10:35", &in1))
printf("Result = failed with conversion error:%d\n",x);
else
printf("Result = successful conversion\n");
/*
* Note that the following literal string has a 26 in the hours field
*/
printf("\nInterval string #2 = 20 26:10:35\n");
if(x = incvasc("20 26:10:35", &in1))
printf("Result = failed with conversion error:%d\n",x);
else
printf("Result = successful conversion\n");
/*
* Try to convert using an invalid qualifier (YEAR to SECOND)
*/
printf("\nInterval string #3 = 2007-02-11 3:10:35\n");
in1.in_qual = TU_IENCODE(4, TU_YEAR, TU_SECOND);
if(x = incvasc("2007-02-11 3:10:35", &in1))
printf("Result = failed with conversion error:%d\n",x);
else
printf("Result = successful conversion\n");
printf("\nINCVASC Sample Program over.\n\n");
}
Output
INCVASC Sample ESQL Program running.
Interval string #1 = 20 3:10:35
Result = successful conversion
Interval string #2 = 20 26:10:35
Result = failed with conversion error:-1263
Interval string #3 = 2007-02-11 3:10:35
Result = failed with conversion error:-1268
INCVASC Sample Program over.