Class: OCI8::BindType::String

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

Direct Known Subclasses

Long

Class Method Summary collapse

Class Method Details

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



221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# File 'lib/oci8/oci8.rb', line 221

def self.create(con, val, param, max_array_size)
  case param
  when Hash
    # 1333 = ceil(4000 (max size of char) / 3 (NLS ratio of UTF8))
    length = 1333 # default length
    if param[:length]
      length = param[:length]
    elsif val.respond_to? :to_str and val.to_str.size > length
      length = val.to_str.size
    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
    else
      length = 100
    end
  end
  self.new(con, val, length, max_array_size)
end