Class: OCI8::BindType::Number

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

Overview

get/set Number (for OCI8::SQLT_NUM)

Class Method Summary collapse

Class Method Details

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



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/oci8/bindtype.rb', line 29

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