Class: OCI8::BindType::DateTime

Inherits:
Object
  • Object
show all
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.

Class Method Summary collapse

Class Method Details

.create(con, val, param, max_array_size) ⇒ Object

:nodoc:



336
337
338
339
340
341
342
# File 'lib/oci8/datetime.rb', line 336

def self.create(con, val, param, max_array_size) # :nodoc:
  if true # TODO: check Oracle server version
    DateTimeViaOCITimestamp.new(con, val, param, max_array_size)
  else
    DateTimeViaOCIDate.new(con, val, param, max_array_size)
  end
end