Class: ODPI::BindType::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/odpi/bindtype.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(conn, array_size, size, size_is_bytes, is_array, objtype) ⇒ Base

Returns a new instance of Base.


48
49
50
51
52
53
# File 'lib/odpi/bindtype.rb', line 48

def initialize(conn, array_size, size, size_is_bytes, is_array, objtype)
  @conn = conn
  @is_array = is_array
  oracle_type, native_type = self.class::TYPES
  @raw_var = Dpi::Var.new(conn, oracle_type, native_type, array_size, size, size_is_bytes, is_array, objtype)
end

Instance Attribute Details

#raw_varObject (readonly)

Returns the value of attribute raw_var


42
43
44
# File 'lib/odpi/bindtype.rb', line 42

def raw_var
  @raw_var
end

Class Method Details

.convert_in(conn, val) ⇒ Object


94
95
96
# File 'lib/odpi/bindtype.rb', line 94

def self.convert_in(conn, val)
  val
end

.convert_out(conn, val) ⇒ Object


98
99
100
# File 'lib/odpi/bindtype.rb', line 98

def self.convert_out(conn, val)
  val
end

.to_bindclass(params) ⇒ Object


44
45
46
# File 'lib/odpi/bindtype.rb', line 44

def self.to_bindclass(params)
  self
end

Instance Method Details

#[](key) ⇒ Object


89
90
91
92
# File 'lib/odpi/bindtype.rb', line 89

def [](key)
  val = @raw_var[key]
  val.nil? ? nil : self.class.convert_out(@conn, val)
end

#[]=(key, val) ⇒ Object


85
86
87
# File 'lib/odpi/bindtype.rb', line 85

def []=(key, val)
  @raw_var[key] = val.nil? ? nil : self.class.convert_in(@conn, val)
end

#getObject


55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/odpi/bindtype.rb', line 55

def get
  if @is_array
    len = @raw_var.num_elements_in_array
    ary = Array.new(len)
    0.upto(len - 1) do |idx|
      ary[idx] = self[idx]
    end
    ary
  else
    self[0]
  end
end

#set(val) ⇒ Object


68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/odpi/bindtype.rb', line 68

def set(val)
  if @is_array
    if val.nil?
      @raw_var.num_elements_in_array = 0
    else
      len = val.length
      @raw_var.num_elements_in_array = len
      0.upto(len - 1) do |idx|
        self[idx] = val[idx]
      end
    end
  else
    self[0] = val
  end
  self
end