Class: OCI8::BindType::DateTime
- Inherits:
-
OCITimestampTZ
- Object
- OCITimestampTZ
- OCI8::BindType::DateTime
- Includes:
- Util
- Defined in:
- lib/oci8/datetime.rb
Overview
– OCI8::BindType::DateTime ++ This is a helper class to select or bind Oracle data types such as DATE
, TIMESTAMP
, TIMESTAMP WITH TIME ZONE
and TIMESTAMP WITH LOCAL TIME ZONE
. The retrieved value is a DateTime.
How to select DataTime values.
DATE
, TIMESTAMP
, TIMESTAMP WITH TIME ZONE
and TIMESTAMP WITH LOCAL TIME ZONE
are selected as a Time by default. You change the behaviour by explicitly calling OCI8::Cursor#define as follows:
cursor = conn.parse("SELECT hiredate FROM emp")
cursor.define(1, nil, DateTime)
cursor.exec()
Otherwise, you can change the default mapping for all queries.
# Changes the mapping for DATE
OCI8::BindType::Mapping[OCI8::SQLT_DAT] = OCI8::BindType::DateTime
# Changes the mapping for TIMESTAMP
OCI8::BindType::Mapping[OCI8::SQLT_TIMESTAMP] = OCI8::BindType::DateTime
# Changes the mapping for TIMESTAMP WITH TIME ZONE
OCI8::BindType::Mapping[OCI8::SQLT_TIMESTAMP_TZ] = OCI8::BindType::DateTime
# Changes the mapping for TIMESTAMP WITH LOCAL TIME ZONE
OCI8::BindType::Mapping[OCI8::SQLT_TIMESTAMP_LTZ] = OCI8::BindType::DateTime
Note for default time zone
The retrieved value’s time zone is determined by the session time zone if its data type is DATE
, TIMESTAMP
or TIMESTAMP WITH LOCAL TIME ZONE
.
The session time zone is same with local machine’s by default. It is changed by the following SQL.
ALTER SESSION SET TIME_ZONE='-05:00'
Note for Oracle 8.x client
Timestamp data types and session time zone are new features in Oracle 9i. This class is available only to fetch or bind DATE
when using Oracle 8.x client.
The retrieved value’s time zone is determined not by the session time zone, but by the OCI8::BindType.default_timezone The time zone can be changed as follows:
OCI8::BindType.default_timezone = :local
# or
OCI8::BindType.default_timezone = :utc
If you are in the regions where daylight saving time is adopted, you should use OCI8::BindType::Time.
Instance Method Summary collapse
-
#get ⇒ Object
:nodoc:.
-
#set(val) ⇒ Object
:nodoc:.
Methods included from Util
default_timezone, default_timezone=
Instance Method Details
#get ⇒ Object
:nodoc:
293 294 295 |
# File 'lib/oci8/datetime.rb', line 293 def get() # :nodoc: array_to_datetime(super(), nil) end |
#set(val) ⇒ Object
:nodoc:
289 290 291 |
# File 'lib/oci8/datetime.rb', line 289 def set(val) # :nodoc: super(datetime_to_array(val, :timestamp_tz)) end |