Class: DBI::DBD::OCI8::BindType::DBITimestamp

Inherits:
OCI8::BindType::OraDate show all
Defined in:
lib/dbd/OCI8.rb

Overview

helper class to define/bind DBI::Timestamp.

To fetch all Oracle’s DATE columns as DBI::Timestamp:

::OCI8::BindType::Mapping[OCI8::SQLT_DAT] = ::DBI::DBD::OCI8::BindType::DBITimestamp

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.decorate(b) ⇒ Object



546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
# File 'lib/dbd/OCI8.rb', line 546

def decorate(b)
  def b.set(val)
    # convert val to an OraDate,
    # then set it to the bind handle.
    super(val && OraDate.new(val.year, val.month, val.day,
                             val.respond_to?(:hour) ? val.hour : 0,
                             val.respond_to?(:min) ? val.min : 0,
                             val.respond_to?(:sec) ? val.sec : 0))
  end
  def b.get()
    # get an Oradate from the bind handle,
    # then convert it to a DBI::Timestamp.
    (val = super()) && DBI::Timestamp.new(val.year, val.month, val.day, val.hour, val.minute, val.second)
  end
end

.fix_type(env, val, length, precision, scale) ⇒ Object



542
543
544
545
# File 'lib/dbd/OCI8.rb', line 542

def fix_type(env, val, length, precision, scale)
  # bind as an OraDate
  [::OCI8::SQLT_DAT, val, nil]
end

Instance Method Details

#getObject



457
458
459
460
461
462
463
# File 'lib/dbd/OCI8.rb', line 457

def get()
  # get an Oradate from the bind handle,
  # then convert it to a DBI::Timestamp.
  val = super()
  return nil if val.nil?
  DBI::Timestamp.new(val.year, val.month, val.day, val.hour, val.minute, val.second)
end

#set(val) ⇒ Object



449
450
451
452
453
454
455
456
# File 'lib/dbd/OCI8.rb', line 449

def set(val)
  # convert val to an OraDate,
  # then set it to the bind handle.
  super(val && OraDate.new(val.year, val.month, val.day,
                           val.respond_to?(:hour) ? val.hour : 0,
                           val.respond_to?(:min) ? val.min : 0,
                           val.respond_to?(:sec) ? val.sec : 0))
end