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



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/oci8/bindtype.rb', line 106

def self.create(con, val, param, max_array_size)
  case param
  when Hash
    param[:length_semantics] = OCI8::properties[:length_semantics] unless param.has_key? :length_semantics
    unless param[:length]
      if val.respond_to? :to_str
        val = val.to_str
        if param[:length_semantics] == :char
          # character semantics
          param[:length] = val.size
        else
          # byte semantics
          if 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
          param[:length] = val.bytesize
        end
      else
        param[:length] = @@minimum_bind_length
      end
    end
    # use the default value when :nchar is not set explicitly.
    param[:nchar] = OCI8.properties[:bind_string_as_nchar] unless param.has_key?(:nchar)
  when OCI8::Metadata::Base
    case param.data_type
    when :char, :varchar2
      length_semantics = OCI8.properties[:length_semantics]
      if length_semantics == :char
        length = param.char_size
      else
        length = param.data_size * OCI8.nls_ratio
      end
      param = {
        :length => length,
        :length_semantics => length_semantics,
        :nchar => (param.charset_form == :nchar),
      }
    when :raw
      # HEX needs twice space.
      param = {:length => param.data_size * 2}
    else
      param = {:length => @@minimum_bind_length}
    end
  end
  self.new(con, val, param, max_array_size)
end

.minimum_bind_lengthObject



98
99
100
# File 'lib/oci8/bindtype.rb', line 98

def self.minimum_bind_length
  @@minimum_bind_length
end

.minimum_bind_length=(val) ⇒ Object



102
103
104
# File 'lib/oci8/bindtype.rb', line 102

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