Class: OCI8::BindType::String

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

Direct Known Subclasses

Long

Constant Summary collapse

@@minimum_bind_length =

1333 <= ceil(4000 / 3). 4000 is max size of char. 3 is NLS ratio of UTF-8.

1333

Class Method Summary collapse

Class Method Details

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



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/oci8/bindtype.rb', line 77

def self.create(con, val, param, max_array_size)
  case param
  when Hash
    if param[:length]
      # If length is passed explicitly, use it.
      length = param[:length]
    elsif val.is_a? String or (val.respond_to? :to_str and val = val.to_str)
      if OCI8.respond_to? :encoding and OCI8.encoding != val.encoding
        # If the string encoding is different with NLS_LANG character set,
        # convert it to get the length.
        val = val.encode(OCI8.encoding)
      end
      if val.respond_to? :bytesize
        # ruby 1.8.7 or upper
        length = val.bytesize
      else
        # ruby 1.8.6 or lower
        length = val.size
      end
    end
  when OCI8::Metadata::Base
    case param.data_type
    when :char, :varchar2
      length = param.data_size
      # character size may become large on character set conversion.
      # The length of a Japanese half-width kana is one in Shift_JIS,
      # two in EUC-JP, three in UTF-8.
      length *= 3 unless param.char_used?
    when :raw
      # HEX needs twice space.
      length = param.data_size * 2
    end
  end
  length = @@minimum_bind_length if length.nil? or length < @@minimum_bind_length
  self.new(con, val, length, max_array_size)
end

.minimum_bind_lengthObject



69
70
71
# File 'lib/oci8/bindtype.rb', line 69

def self.minimum_bind_length
  @@minimum_bind_length
end

.minimum_bind_length=(val) ⇒ Object



73
74
75
# File 'lib/oci8/bindtype.rb', line 73

def self.minimum_bind_length=(val)
  @@minimum_bind_length = val
end