Class: OCI8::BindType::Number

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

Overview

get/set Number (for OCI8::SQLT_NUM)

Class Method Summary collapse

Class Method Details

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



184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/oci8/oci8.rb', line 184

def self.create(con, val, param, max_array_size)
  if param.is_a? OCI8::Metadata::Base
    precision = param.precision
    scale = param.scale
  end
  if scale == -127
    if precision == 0
      # NUMBER declared without its scale and precision. (Oracle 9.2.0.3 or above)
      klass = OCI8::BindType::Mapping[:number_no_prec_setting]
    else
      # FLOAT or FLOAT(p)
      klass = OCI8::BindType::Float
    end
  elsif scale == 0
    if precision == 0
      # NUMBER whose scale and precision is unknown
      # or
      # NUMBER declared without its scale and precision. (Oracle 9.2.0.2 or below)
      klass = OCI8::BindType::Mapping[:number_unknown_prec]
    else
      # NUMBER(p, 0)
      klass = OCI8::BindType::Integer
    end
  else
    # NUMBER(p, s)
    if precision < 15 # the precision of double.
      klass = OCI8::BindType::Float
    else
      # use BigDecimal instead?
      klass = OCI8::BindType::OraNumber
    end
  end
  klass.new(con, val, nil, max_array_size)
end