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



531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
# File 'lib/dbd/OCI8.rb', line 531

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



527
528
529
530
# File 'lib/dbd/OCI8.rb', line 527

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

Instance Method Details

#getObject



442
443
444
445
446
447
448
# File 'lib/dbd/OCI8.rb', line 442

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



434
435
436
437
438
439
440
441
# File 'lib/dbd/OCI8.rb', line 434

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