Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bind_param: when value is nil, use String as default type #60

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions lib/oci8/cursor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ def define(pos, type, length = nil)
# cursor.exec()
# cursor.close()
def bind_param(key, param, type = nil, length = nil)
if type.nil? and param.nil?
type = String
length = 1 unless length
end
case param
when Hash
when Class
Expand Down Expand Up @@ -288,18 +292,19 @@ def bind_param_array(key, var_array, type = nil, max_item_length = nil)
raise "all binding arrays should be the same size." unless @actual_array_size.nil? || var_array.size == @actual_array_size
@actual_array_size = var_array.size if @actual_array_size.nil?
end

param = {:value => var_array, :type => type, :length => max_item_length, :max_array_size => @max_array_size}
first_non_nil_elem = var_array.nil? ? nil : var_array.find{|x| x!= nil}

if type.nil?
if first_non_nil_elem.nil?
raise "bind type is not given."
type = String #raise "bind type is not given."
max_item_length = 1 unless max_item_length
else
type = first_non_nil_elem.class
end
end

bindclass = OCI8::BindType::Mapping[type]
if bindclass.nil? and type.is_a? Class
bindclass = OCI8::BindType::Mapping[type.to_s]
Expand Down