13.16 IntervalYM Class
IntervalYM
supports the SQL standard data type Year-Month Interval.
Leading field precision is determined by number of decimal digits on input.
Table 13-21 Fields of IntervalYM Class
Field | Type | Description |
---|---|---|
|
|
Year component. Valid values are |
|
|
Month component. Valid values are |
Example 13-8 How to Use an Empty IntervalYM Object Through Direct Assignment
This example demonstrates that the default constructor creates a NULL
value, and how you can assign a non NULL
value to a year-month interval and then perform operations on it:
Environment *env = Environment::createEnvironment(); // Create a NULL year-month interval IntervalYM ym if(ym.isNull()) cout << "\n ym is null"; // Assign a non-NULL value to ym IntervalYM anotherYM(env, "10-30"); ym=anotherYM; // Now all operations on YM are valid int yr = ym.getYear();
Example 13-9 How to Use an IntervalYM Object Through ResultSet and toText() Method
This example demonstrates how to get the year-month interval column from a result set, add to the year-month interval by using the +=
operator, multiply by using the *
operator, compare 2 year-month intervals, and convert a year-month interval to a string by using the toText()
method.
//SELECT WARRANT_PERIOD from PRODUCT_INFORMATION //obtain result set resultset->next(); //get interval value from resultset IntervalYM ym1 = resultset->getIntervalYM(1); IntervalYM addWith(env, 10, 1); ym1 += addWith; //call += operator IntervalYM mulYm1 = ym1 * Number(env, 10); //call * operator if(ym1<mulYm1) //comparison . . string strym = ym1.toText(3); //3 is the leading field precision
Table 13-22 Summary of IntervalYM Methods
Method | Summary |
---|---|
|
|
Converts a |
|
Converts a |
|
Returns month interval value. |
|
Returns year interval value. |
|
Checks if the interval is |
|
Returns the product of two |
|
Multiplication assignment. |
|
Simple assignment. |
|
Checks if |
|
Checks if |
|
Returns an |
|
Division assignment. |
|
Checks if |
|
Checks if |
|
Checks if |
|
Checks if |
|
Returns an |
|
Subtraction assignment. |
|
Returns the sum of two |
|
Addition assignment. |
|
Sets the interval to the values specified. |
|
Sets the interval to |
|
Converts to a |
|
Converts to a |
13.16.1 IntervalYM()
IntervalYM class constructor.
Syntax | Description |
---|---|
IntervalYM(); |
Constructs a |
IntervalYM( const Environment *env, int year = 0, int month = 0); |
Creates an |
IntervalDS( const IntervalYM &src); |
Copy constructor. |
Parameter | Description |
---|---|
env |
The |
year |
The |
month |
The |
src |
The source that the |
13.16.2 fromText()
This method initializes the interval to the values in inpstr
. The string is interpreted using the NLS parameters set in the environment.
The NLS parameters are picked up from env
. If env
is NULL
, the NLS parameters are picked up from the environment associated with the instance, if any.
Syntax
void fromText( const string &inpStr, const string &nlsParam = "", const Environment *env = NULL);
Parameter | Description |
---|---|
inpStr |
Input string representing a year month interval of the form 'year-month'. |
nlsParam |
The NLS parameters string. If |
env |
Environment whose NLS parameters are used. |
13.16.3 fromUText()
Creates the interval from the UString
specified.
Syntax
void fromUText( const UString &inpStr, const Environment *env=NULL );
Parameter | Description |
---|---|
inpStr |
Input |
env |
The |
13.16.4 getMonth()
This method returns the month component of the interval.
Syntax
int getMonth() const;
13.16.5 getYear()
This method returns the year component of the interval.
Syntax
int getYear() const;
13.16.6 isNull()
This method tests whether the interval is NULL
. If the interval is NULL
then TRUE
is returned; otherwise, FALSE
is returned.
Syntax
bool isNull() const;
13.16.7 operator*()
This method multiplies the interval by a factor and returns the result.
Syntax
const IntervalYM operator*( const IntervalDS &interval const Number &val);
Parameter | Description |
---|---|
interval |
Interval to be multiplied. |
val |
Value by which interval is to be multiplied. |
13.16.8 operator*=()
This method multiplies the interval by a specified value.
Syntax
IntervalYM& operator*=( const Number &factor);
Parameter | Description |
---|---|
factor |
Value to be multiplied. |
13.16.9 operator=()
This method assigns the specified value to the interval.
Syntax
IntervalYM& operator=( const IntervalYM &src);
Parameter | Description |
---|---|
src |
Value to be assigned. |
13.16.10 operator==()
This method compares the intervals specified. If the intervals are equal then TRUE
is returned; otherwise, FALSE
is returned. If either interval is NULL
then SQLException is thrown.
Syntax
bool operator==(
const IntervalYM &first,
const IntervalYM &second
);
Parameter | Description |
---|---|
first |
The first interval to be compared. |
second |
The second interval to be compared. |
13.16.11 operator!=()
This method compares the intervals specified. If the intervals are not equal then TRUE
is returned; otherwise, FALSE
is returned. If either interval is NULL
then SQLException is thrown.
Syntax
bool operator!=( const IntervalYM &first, const IntervalYM &second);
Parameter | Description |
---|---|
first |
The first interval to be compared. |
second |
The second interval to be compared. |
13.16.12 operator/()
This method returns the result of dividing the interval by a factor.
Syntax
const IntervalYM operator/( const IntervalYM ÷nd, const Number &factor);
Parameter | Description |
---|---|
dividend |
The interval to be divided. |
factor |
Value by which interval is to be divided. |
13.16.13 operator/=()
This method divides the interval by a factor.
Syntax
IntervalYM& operator/=( const Number &factor);
Parameter | Description |
---|---|
factor |
A day second interval. |
13.16.14 operator>()
This method compares the intervals specified. If the first interval is greater than the second interval then TRUE
is returned; otherwise, FALSE
is returned. If either interval is NULL
then SQLException is thrown.
Syntax
bool operator>( const IntervalYM &first, const IntervalYM &second);
Parameter | Description |
---|---|
first |
The first interval to be compared. |
second |
The second interval to be compared. |
13.16.15 operator>=()
This method compares the intervals specified. If the first interval is greater than or equal to the second interval then TRUE
is returned; otherwise, FALSE
is returned. If either interval is NULL
then SQLException is thrown.
Syntax
bool operator>=( const IntervalYM &first, const IntervalYM &second);
Parameter | Description |
---|---|
first |
The first interval to be compared. |
second |
The second interval to be compared. |
13.16.16 operator<()
This method compares the intervals specified. If the first interval is less than the second interval then TRUE
is returned; otherwise, FALSE
is returned. If either interval is NULL
then SQLException is thrown.
Syntax
bool operator<( const IntervalYM &first, const IntervalYM &second);
Parameter | Description |
---|---|
first |
The first interval to be compared. |
second |
The second interval to be compared. |
13.16.17 operator<=()
This method compares the intervals specified. If the first interval is less than or equal to the second interval then TRUE
is returned; otherwise, FALSE
is returned. If either interval is NULL
then SQLException is thrown
Syntax
bool operator<=( const IntervalYM &first, const IntervalYM &second);
Parameter | Description |
---|---|
first |
The first interval to be compared. |
second |
The second interval to be compared. |
13.16.18 operator-()
This method returns the difference between the intervals specified.
Syntax
const IntervalYM operator-( const IntervalYM &first, const IntervalYM &second);
Parameter | Description |
---|---|
first |
The first interval to be compared. |
second |
The second interval to be compared. |
13.16.19 operator-=
()
This method computes the difference between itself and another interval.
Syntax
IntervalYM& operator-=( const IntervalYM &val);
Parameter | Description |
---|---|
val |
A day second interval. |
13.16.20 operator+()
This method returns the sum of the intervals specified.
Syntax
const IntervalYM operator+(
const IntervalYM &first,
const IntervalYM &second
);
Parameter | Description |
---|---|
first |
The first interval to be compared. |
second |
The second interval to be compared. |
13.16.21 operator+=()
This method assigns the sum of IntervalYM
and val
to IntervalYM
.
Syntax
IntervalYM& operator+=( const IntervalYM &val);
Parameter | Description |
---|---|
val |
A day second interval. |
13.16.22 set()
This method sets the interval to the values specified.
Syntax
void set( int year, int month);
Parameter | Description |
---|---|
year |
Year component. Valid values are |
month |
Month component. Valid values are |
13.16.24 toText()
This method returns the string representation of the interval.
Syntax
string toText( unsigned int lfprec, const string &nlsParam = "") const;
Parameter | Description |
---|---|
lfprec |
Leading field precision. |
nlsParam |
The NLS parameters string. If |