Oracle C++ Call Interface Programmer's Guide Release 2 (9.2) Part Number A96583-01 |
|
OCCI Classes and Methods, 8 of 22
The Date class specifies the abstraction for a SQL DATE data item. The Date class also adds formatting and parsing operations to support the OCCI escape syntax for date values.
Since SQL92 DATE is a subset of Oracle Date, this class can be used to support both.
To create a null Date
object, use the syntax:
Date();
To create a copy of a Date
object, use the syntax:
Date(const Date &a);
To create a Date
object using integer parameters, where:
Variable | Value |
---|---|
year |
-4712 to 9999, except 0 |
month |
1 to 12 |
day |
1 to 31 |
minutes |
0 to 59 |
seconds |
0 to 59 |
use the syntax:
Date(const Environment *envp, int year = 1, unsigned int month = 1, unsigned int day = 1, unsigned int hour = 0, unsigned int minute = 0, unsigned int seconds = 0);
Objects from the Date class can be used as standalone class objects in client side numerical computations and also used to fetch from and set to the database.
The following code example demonstrates a Date column value being retrieved from the database, a bind using a Date object, and a computation using a standalone Date object:
/* Create a connection */ Environment *env = Environment::createEnvironment(Environment::DEFAULT); Connection *conn = env->createConnection(user, passwd, db); /* Create a statement and associate a DML statement to it */ string sqlStmt = "SELECT job-id, start_date from JOB_HISTORY where end_date = :x"; Statement *stmt = conn->createStatement(sqlStmt); /* Create a Date object and bind it to the statement */ Date edate(env, 2000, 9, 3, 23, 30, 30); stmt->setDate(1, edate); ResultSet *rset = stmt->executeQuery(); /* Fetch a date from the database */ while(rset->next()) { Date sd = rset->getDate(2); Date temp = sd; /*assignment operator */ /* Methods on Date */ temp.getDate(year, month, day, hour, minute, second); temp.setMonths(2); IntervalDS inter = temp.daysBetween(sd); . . . }
This method adds a specified number of days to the Date
object and returns the new date.
Date addDays(int i) const;
The number of days to be added to the current Date
object.
This method adds a specified number of months to the Date
object and returns the new date.
Date addMonths(int i) const;
The number of months to be added to the current Date
object.
This method returns the number of days between the current Date
object and the date specified
.
IntervalDS daysBetween(const Date &d) const;
The date to be used to compute the days between.
This method converts a Bytes
object to a Date
object.
void fromBytes(const Bytes &byteStream, const Environment *envp = NULL);
Date
in external format in the form of Bytes.
The OCCI environment.
This method converts a string object to a Date
object.
void fromText(const string &datestr, const string &fmt = "", const string &nlsParam = "", const Environment *envp = NULL);
The date string to be converted.
The format string.
A string specifying the nls parameters to be used.
The environment from which the nls parameters are to be obtained.
This method returns the date in the form of the date components year, month, day, hour, minute, seconds.
void getDate(int &year, unsigned int &month, unsigned int &day, unsigned int &hour, unsigned int &min, unsigned int &sec) const;
The year component of the date.
The month component of the date.
The day component of the date.
The hour component of the date.
The minutes component of the date.
The seconds component of the date.
This method returns the system date.
static Date getSystemDate(const Environment *envp);
The environment in which the system date is returned.
This method tests whether the Date
is null. If the Date
is null, true is returned; otherwise, false is returned.
bool isNull() const;
This method returns a date representing the last day of the current month.
Date lastDay() const;
This method returns a date representing the day after the day of the week specified.
Date nextDay(const string &dow) const;
A string representing the day of the week.
This method assigns the date object on the right side of the equal (=) sign to the date object on the left side of the equal (=) sign.
Date& operator=(const Date &d);
The date object that is assigned.
This method compares the dates specified. If the dates are equal, true is returned; otherwise, false is returned.
bool operator==(const Date &a, const Date &b);
The dates that are compared for equality.
This method compares the dates specified. If the dates are not equal then true is returned; otherwise, false is returned.
bool operator!=(const Date &a, const Date &b);
The dates that are compared for inequality.
This method compares the dates specified. If the first date is in the future relative to the second date then true is returned; otherwise, false is returned. If either date is null then false is returned. If the dates are
not the same type then false is returned.
bool operator>(const Date &a, const Date &b);
The dates that are compared.
This method compares the dates specified. If the first date is in the future relative to the second date or the dates are equal then true is returned; otherwise, false is returned. If either date is null then false is returned. If the dates are not the same type then false is returned.
bool operator>=(const Date &a, const Date &b);
The dates that are compared.
This method compares the dates specified. If the first date is in the past relative to the second date then true is returned; otherwise, false is returned. If either date is null then false is returned. If the dates are not the same type then false is returned.
bool operator<(const Date &a, const Date &b);
The dates that are compared.
This method compares the dates specified. If the first date is in the past relative to the second date or the dates are equal then true is returned; otherwise, false is returned. If either date is null then false is returned. If the dates are not the same type then false is returned.
bool operator<=(const Date &a, const Date &b);
The dates that are compared.
This method sets the date to the values specified.
void setDate(int year = 1, unsigned int month = 1, unsigned int day = 1, unsigned int hour = 0, unsigned int minute = 0, unsigned int seconds = 0);
The argument specifying the year value.
Valid values are -4713 through 9999.
The argument specifying the month value.
Valid values are 1 through 12.
The argument specifying the day value.
Valid values are 1 through 31.
The argument specifying the hour value.
Valid values are 0 through 23.
The argument specifying the minutes value.
Valid values are 0 through 59 .
The argument specifying the seconds value.
Valid values are 0 through 59.
This method set the date to atomically null.
void setNull();
This method returns the date in Bytes
representation.
Bytes toBytes() const;
This method returns a string with the value of this date formatted using fmt
and nlsParam
.
string toText(const string &fmt = "", const string &nlsParam = "") const;
The format string.
A string specifying the nls parameters to be used.
This method returns Date
value converted from one time zone to another
.
Valid values are:
Date toZone(const string &zone1, const string &zone2) const;
A string representing the time zone to be converted from.
A string representing the time zone to be converted to.
|
Copyright © 2001, 2002 Oracle Corporation. All Rights Reserved. |
|