Class: OCI8::InCondBindHelper
- Inherits:
-
Object
- Object
- OCI8::InCondBindHelper
- Defined in:
- lib/oci8/oci8.rb
Overview
A helper class to bind an array to paramters in IN-condition.
Instance Method Summary collapse
-
#initialize(bind_name_prefix, array, type = nil, length = nil) ⇒ InCondBindHelper
constructor
A new instance of InCondBindHelper.
- #names ⇒ Object
- #values ⇒ Object
Constructor Details
#initialize(bind_name_prefix, array, type = nil, length = nil) ⇒ InCondBindHelper
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 482 |
# File 'lib/oci8/oci8.rb', line 456 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 |