informix
Informix JDBC Driver Programmer's Guide
Manipulating Informix Data Types

Manipulating Informix INTERVAL Data Types

The Informix INTERVAL data type stores a value that represents a span of time. INTERVAL data types are divided into two types: year-month intervals and day-time intervals. A year-month interval can represent a span of years and months, and a day-time interval can represent a span of days, hours, minutes, seconds, and fractions of a second. For more information about the INTERVAL data type and definitions of qualifier, precision, and fraction, refer to the following manuals:

The Interval Class

The com.informix.lang.Interval class is an Informix-specific extension to the JDBC 2.0 specification from Sun Microsystems. Interval is the base class for the INTERVAL data type. Interval has two subclasses: IntervalYM (for year-month qualifiers) and IntervalDF (for day-time qualifiers). You use these subclasses to actually create and manipulate INTERVAL data types.

Variables for Binary Qualifiers

You can use string qualifiers to manipulate INTERVAL data types, but using binary qualifiers results in faster performance. The following variables are defined in the Interval base class and represent the time unit (start and end code) of a field in the binary qualifier.

Variable Description
TU_YEAR Time unit for the YEAR qualifier field
TU_MONTH Time unit for the MONTH qualifier field
TU_DAY Time unit for the DAY qualifier field
TU_HOUR Time unit for the HOUR qualifier field
TU_MINUTE Time unit for the MINUTE qualifier field
TU_SECOND Time unit for the SECOND qualifier field
TU_FRAC Time unit for the leading FRACTION qualifier field
TU_F1 Time unit for the ending field of the first position of FRACTION
TU_F2 Time unit for the ending field of the second position of FRACTION
TU_F3 Time unit for the ending field of the third position of FRACTION
TU_F4 Time unit for the ending field of the fourth position of FRACTION
TU_F5 Time unit for the ending field of the fifth position of FRACTION

The IntervalYM and IntervalDF classes inherit these variables from the Interval base class.

Interval Methods

You can use the following methods to extract information about binary qualifiers. Here are the signatures and descriptions of each method:

This method extracts the ending field code (one of the TU_XXX variables) from a qualifier.

This method takes the TU_XXX value of part of an interval and returns the string value. For example, getFieldName(TU_YEAR) returns the string YEAR.

This method takes a qualifier and returns the entire name of the interval in string form.

This method extracts the length of a qualifier.

This method creates a binary qualifier from a length, start code (TU_XXX), and end code (TU_XXX). For example, getQualifier(4, TU_YEAR, TU_MONTH) creates a binary representation of the YEAR TO MONTH qualifier.

This method returns the number of digits in the FRACTION part of a day-time qualifier.

This method extracts the starting field code (one of the TU_XXX variables) from a qualifier.

The IntervalYM and IntervalDF classes inherit these methods from Interval.

The IntervalYM Class

The com.informix.lang.IntervalYM class allows you to manipulate year-month intervals.

IntervalYM Constructors

The following constructors allow you to create year-month intervals. Here are the signatures and descriptions of each constructor:

This is the default constructor.

This constructor creates an interval from two timestamps.

This constructor creates a year-month interval from year and month values. Large month values are converted to years.

This constructor creates a year-month interval from a string. For information about string INTERVAL formats, refer to the Informix Guide to SQL: Syntax.

This constructor creates a year-month interval from a string and qualifier information. For information about string INTERVAL formats, refer to the Informix Guide to SQL: Syntax.

IntervalYM Methods

The following methods allow you to manipulate year-month intervals. Here are the signatures and descriptions of each method:

This method compares two intervals for equality.

This method sets the values for the interval from a string.

This method returns the number of months in the interval.

This method compares the first interval to the second to see if the first is longer.

This method compares the first interval to the second to see if the second is longer.

This method sets the values for the interval from year and month values. Large month values are converted to years.

This method sets the values for the interval from a string.

This method sets the values for the interval from two timestamps.

This method sets the qualifier from the length, start code, and end code.

This method sets the qualifier using an existing qualifier.

This method creates a string representation of the interval in the format yyyy-mm. The fields present depend on the qualifier. Blanks replace leading zeros.

The IntervalDF Class

The com.informix.lang.IntervalDF class allows you to manipulate day-time intervals.

IntervalDF Constructors

The following constructors allow you to create day-time intervals. Here are the signatures and descriptions of each constructor:

This is the default constructor.

This constructor creates an interval from two timestamps.

This constructor creates a day-time interval from second and nanosecond values. Large second values are converted to minutes, hours, or days.

This constructor creates a day-time interval from a string. For information about string INTERVAL formats, refer to the Informix Guide to SQL: Syntax.

This constructor creates a day-time interval from a string and qualifier information. For information about string INTERVAL formats, refer to the Informix Guide to SQL: Syntax.

IntervalDF Methods

The following methods allow you to manipulate day-time intervals. Here are the signatures and descriptions of each method:

This method compares two intervals for equality.

This method sets the values for the interval from a string.

This method returns the number of nanoseconds in the interval.

This method returns the number of seconds in the interval.

This method compares the first interval to the second to see if the first is longer.

This method compares the first interval to the second to see if the second is longer.

This method sets the values for the interval from second and nanosecond values. Large second values are converted to minutes, hours, or days.

This method sets the values for the interval from a string.

This method sets the values for the interval from two timestamps.

This method sets the qualifier from the length, start code, and end code.

This method creates a string representation of the interval in the format ddddd hh:mm:ss.nano. The fields present depend on the qualifier. Blanks replace leading zeros.

Interval Example

The Intervaldemo.java program, which is included in Informix JDBC Driver, shows how to insert into and select from the two types of INTERVAL data types.


Informix JDBC Driver Programmer's Guide, Version 2.0
Copyright © 1999, Informix Software, Inc. All rights reserved