Oracle C++ Call Interface Programmer's Guide Release 2 (9.2) Part Number A96583-01 |
|
OCCI Classes and Methods, 22 of 22
This class conforms to the SQL92 TIMESTAMP and TIMESTAMPTZ types.
OCCI expects the SQL data type corresponding to the Timestamp
class to be of type TIMESTAMP WITH TIME ZONE.
Timestamp(const Environment *env, int year = 1, unsigned int month = 1, unsigned int day = 1, unsigned int hour = 0, unsigned int min = 0, unsigned int sec = 0, unsigned int fs = 0, int tzhour = 0 int tzmin=0
A SQLException
will occur if a parameter is out of range.
year - -4713 to 9999
month 1 to 12
day - 1 to 31
hour - 0 to 23
min - 0 to 59
sec - 0 to 61
tzhour - -12 to 14
tzmin - -59 to 59
Returns a null Timestamp
object. A null timestamp can be initialized by assignment or calling the fromText
method. Methods that can be called on null timestamp objects are setNull
, isNull and operator=()
.
Timestamp();
Assigns the values found in a
.
Timestamp(const Timestamp &src);
The following code example demonstrates that the default constructor creates a null value, and how you can assign a non null value to a timestamp and perform operations on it:
Environment *env = Environment::createEnvironment(); //create a null timestamp Timestamp ts; if(ts.isnull()) cout << "\n ts is Null"; //assign a non null value to ts Timestamp notNullTs(env, 2000, 8, 17, 12, 0, 0, 0, 5, 30); ts = notNullTs; //now all operations are valid on ts... int yr; unsigned int mth, day; ts.getDate(yr, mth, day);
The following code example demonstrates how to use the fromText
method to initialize a null timestamp:
Environment *env = Environment::createEnvironment(); Timestamp ts1; ts1.fromText("01:16:17.12 04/03/1825", "hh:mi:ssxff dd/mm/yyyy", "", env);
The following code example demonstrates how to get the timestamp column from a result set, check whether the timestamp is null, get the timestamp value in string format, and determine the difference between 2 timestamps:
Timestamp reft(env, 2001, 1, 1); ResultSet *rs=stmt->executeQuery("select order_date from orders where customer_id=1"); rs->next(); //retrieve the timestamp column from result set Timestamp ts=rs->getTimestamp(1); //check timestamp for null if(!ts.isNull()) { //get the timestamp value in string format string tsstr=ts.toText("dd/mm/yyyy hh:mi:ss [tzh:tzm]",0); if(reft<ts //compare timestamps { IntervalDS ds=reft.subDS(ts); //get difference between timestamps } }
This method sets the timestamp value from the string. The string is expected to be in the format specified. If nlsParam
is specified, this will determine the nls parameters to be used for the conversion. If nlsParam
is not specified, the nls parameters are picked up from the environment which has been passed. In case environment is not passed, NLS parameters are obtained from the environment associated with the instance, if any.
void fromText(const string ×tmpStr, const string &fmt, const string &nlsParam = "", const Environment *env = NULL);
input string
format string
language name
current support for English and American
environment whose nls params will be used.
Return the year, day, and month values of the Timestamp
.
void getDate(int &year, unsigned int &month, unsigned int &day) const;
year component
month component
day component
Return the hour, minute, second, and fractional second (fs) components
void getTime(unsigned int &hour, unsigned int &minute, unsigned int &second, unsigned int &fs) const;
hour component
minute component
second component
fractional second component
Returns the time zone offset in hours and minutes.
void getTimeZoneOffset(int &hour, int &minute) const;
time zone hour
time zone minute
Adds an interval to timestamp .
There are variants of syntax:
Timestamp intervalAdd(const IntervalDS& val) const;
Timestamp intervalAdd(const IntervalYM& val) const;
interval to be added
Subtracts an interval from a timestamp and returns the result as a timestamp.
Returns a Timestamp
with the value of this - val
.
There are variants of syntax:
Timestamp intervalSub(const IntervalDS& val) const;
Timestamp intervalSub(const IntervalYM& val) const;
interval to be subtracted
Returns true
if Timestamp
is null or false
otherwise.
bool isNull() const;
Assigns a given timestamp object to this object.
Timestamp & operator=(const Timestamp &src);
value to be assigned
This method compares the timestamps specified. If the timestamps are equal Returns true
if a is the same as b
, false
otherwise. If either a
or b
is null then false is returned.
bool operator==(const Timestamp &a,
const Timestamp &b
);
Timestamps to be compared.
This method compares the timestamps specified. If the timestamps are not equal then true is returned; otherwise, false is returned. If either timestamp is null then false is returned.
bool operator!=(const Timestamp &a, const Timestamp &b);
Timestamps to be compared.
Returns true
if a is greater than b
, false
otherwise. If either a
or b
is null then false is returned.
bool operator>(const Timestamp &a,
const Timestamp &b
);
Timestamps to be compared.
This method compares the timestamps specified. If the first timestamp is greater than or equal to the second timestamp then true is returned; otherwise, false is returned. If either timestamp is null then false is returned.
bool operator>=(const Timestamp &a, const Timestamp &b);
Timestamps to be compared.
Returns true
if a
is less than b
, false
otherwise. If either a
or b
is null then false is returned.
bool operator<(const Timestamp &a,
const Timestamp &b
);
Timestamps to be compared.
This method compares the timestamps specified. If the first timestamp is less than or equal to the second timestamp then true is returned; otherwise, false is returned. If either timestamp is null then false is returned
bool operator<=(const Timestamp &a, const Timestamp &b);
Timestamps to be compared.
Sets the year, month, day components contained for this timestamp
void setDate(int year, unsigned int month, unsigned int day);
year component to be set.
Valid values are -4713 through 9999.
month component to be set.
Valid values are 1 through 12.
day component to be set.
Valid values are 1 through 31.
Set the timestamp to null.
void setNull();
Sets the day, hour, minute, second and fractional second components for this timestamp.
void setTime(unsigned int hour, unsigned int minute, unsigned int second, unsigned int fs);
hour component.
Valid values are 0 through 23.
minute component.
Valid values are 0 through 59.
second component.
Valid values are 0 through 59.
fractional second component.
Sets the hour and minute offset for time zone.
void setTimeZoneOffset(int hour, int minute);
time zone hour.
Valid values are -12 through 14.
time zone minute.
Valid values are -59 through 59.
Compute the difference between this timestamp and the specified timestamp and return the difference as an IntervalDS
.
IntervalDS subDS(const Timestamp& val) const;
Tmestamp to be subtracted.
Compute the difference between timestamp values and return the difference as an IntervalYM
.
IntervalYM subYM(const Timestamp& val) const;
Timestamp to be subtracted.
Return string representation for the timestamp in the format specified. If nlsParam
is specified, this will determine the nls parameters to be used for the conversion. If nlsParam
is not specified, the nls parameters are picked up from the environment associated with the instance, if any.
string toText(const string &fmt, unsigned int fsprec, const string &nlsParam = "") const;
Format string.
Precision required for the fractional seconds component.
Current support only for English, American.
See Also:
|
|
Copyright © 2001, 2002 Oracle Corporation. All Rights Reserved. |
|