Class: OCI8::InCondBindHelper

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

Overview

A helper class to bind an array to paramters in IN-condition.

See Bind an Array to IN-condition

Instance Method Summary collapse

Constructor Details

#initialize(bind_name_prefix, array, type = nil, length = nil) ⇒ InCondBindHelper

Returns a new instance of InCondBindHelper.



455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
# File 'lib/oci8/oci8.rb', line 455

def initialize(bind_name_prefix, array, type = nil, length = nil)
  bind_name_prefix = bind_name_prefix.to_s
  if bind_name_prefix !~ /^\w+$/
    raise ArgumentError, "The first argument doesn't consist of alphanumeric characters and underscores."
  end
  if array.empty?
    # This doesn't match anything.
    # However in-condition requires at least one value.
    @bind_names = ":#{bind_name_prefix}_0"
    @bind_values = [[nil, type.nil? ? String : type, length]]
  else
    @bind_names = Array.new(array.length) do |index|
      ":#{bind_name_prefix}_#{index}"
    end.join(', ')
    first_non_nil = array.find do |e|
      !e.nil?
    end
    first_non_nil = '' if first_non_nil.nil?
    @bind_values = array.collect do |elem|
      if elem.nil? and type.nil?
        [elem, first_non_nil.class]
      else
        [elem, type, length]
      end
    end
  end
end

Instance Method Details

#namesObject



483
484
485
# File 'lib/oci8/oci8.rb', line 483

def names
  @bind_names
end

#valuesObject



487
488
489
# File 'lib/oci8/oci8.rb', line 487

def values
  @bind_values
end