Class: OCI8::BindType::Time

Inherits:
OCITimestampTZ
  • Object
show all
Includes:
Util
Defined in:
lib/oci8/datetime.rb

Overview

– OCI8::BindType::Time ++ 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 Time.

How to select Time values.

DATE, TIMESTAMP, TIMESTAMP WITH TIME ZONE and TIMESTAMP WITH LOCAL TIME ZONE are selected as a Time by default. If the default behaviour is changed, you can select it as a Time by explicitly calling OCI8::Cursor#define as follows:

cursor = conn.parse("SELECT hiredate FROM emp")
cursor.define(1, nil, Time)
cursor.exec()

Note for ruby prior to 1.9.2

If the retrieved value cannot be represented by Time, it become a DateTime. The fallback is done only when the ruby is before 1.9.2 and one of the following conditions are met.

  • The timezone part is neither local nor utc.

  • The time is out of the time_t.

If the retrieved value has the precision of fractional second more than 6, the fractional second is truncated to microsecond, which is the precision of standard Time class.

To avoid this fractional second truncation:

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

Instance Method Summary collapse

Methods included from Util

default_timezone, default_timezone=

Instance Method Details

#getObject

:nodoc:



394
395
396
# File 'lib/oci8/datetime.rb', line 394

def get() # :nodoc:
  array_to_time(super(), nil)
end

#set(val) ⇒ Object

:nodoc:



390
391
392
# File 'lib/oci8/datetime.rb', line 390

def set(val) # :nodoc:
  super(datetime_to_array(val, :timestamp_tz))
end