Class: OCI8::OracleVersion

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

Overview

The data class, representing Oracle version.

Oracle version is represented by five numbers: major, minor, update, patch and port_update.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arg, minor = nil, update = nil, patch = nil, port_update = nil) ⇒ OCI8::OracleVersion

Creates an OCI8::OracleVersion object.

If the first argument arg is a String, it is parsed as dotted version string. If it is bigger than 0x08000000, it is parsed as a number contains 5-digit Oracle version. Otherwise, it is used as a major version and the rest arguments are minor, update, patch and port_update. Unspecified version numbers are zeros by default.

Examples:

# When the first argument is a String,
oraver = OCI8::OracleVersion.new('11.2.0.3')
oraver.major       # => 11
oraver.minor       # =>  2
oraver.update      # =>  0
oraver.patch       # =>  3
oraver.port_update # =>  0

# When the first argument is bigger than 0x08000000,
oraver = OCI8::OracleVersion.new(0x0b200300)
oraver.major       # => 11
oraver.minor       # =>  2
oraver.update      # =>  0
oraver.patch       # =>  3
oraver.port_update # =>  0

# Otherwise,
oraver = OCI8::OracleVersion.new(11, 2, 0, 3)
oraver.major       # => 11
oraver.minor       # =>  2
oraver.update      # =>  0
oraver.patch       # =>  3
oraver.port_update # =>  0

64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/oci8/oracle_version.rb', line 64

def initialize(arg, minor = nil, update = nil, patch = nil, port_update = nil)
  if arg.is_a? String
    major, minor, update, patch, port_update = arg.split('.').collect do |v|
      v.to_i
    end
  elsif arg >= 0x12000000
    major  = (arg & 0xFF000000) >> 24
    minor  = (arg & 0x00FF0000) >> 16
    update = (arg & 0x0000F000) >> 12
    patch  = (arg & 0x00000FF0) >>  4
    port_update = (arg & 0x0000000F)
  elsif arg >= 0x08000000
    major  = (arg & 0xFF000000) >> 24
    minor  = (arg & 0x00F00000) >> 20
    update = (arg & 0x000FF000) >> 12
    patch  = (arg & 0x00000F00) >> 8
    port_update = (arg & 0x000000FF)
  else
    major = arg
  end
  @major = major
  @minor = minor || 0
  @update = update || 0
  @patch = patch || 0
  @port_update = port_update || 0
  @vernum = if @major >= 18
              (@major << 24) | (@minor << 16) | (@update << 12) | (@patch << 4) | @port_update
            else
              (@major << 24) | (@minor << 20) | (@update << 12) | (@patch << 8) | @port_update
            end
end

Instance Attribute Details

#majorObject (readonly)

The first part of the Oracle version.


19
20
21
# File 'lib/oci8/oracle_version.rb', line 19

def major
  @major
end

#minorObject (readonly)

The second part of the Oracle version.


21
22
23
# File 'lib/oci8/oracle_version.rb', line 21

def minor
  @minor
end

#patchObject (readonly)

The fourth part of the Oracle version.


25
26
27
# File 'lib/oci8/oracle_version.rb', line 25

def patch
  @patch
end

#port_updateObject (readonly)

The fifth part of the Oracle version.


27
28
29
# File 'lib/oci8/oracle_version.rb', line 27

def port_update
  @port_update
end

#updateObject (readonly)

The third part of the Oracle version.


23
24
25
# File 'lib/oci8/oracle_version.rb', line 23

def update
  @update
end

Instance Method Details

#<=>(other) ⇒ -1, ...

Compares self and other.

<=> is the basis for the methods <, <=, ==, >, >=, and between?, included from the Comparable module.

Returns:

  • (-1, 0, +1)

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

def <=>(other)
  @vernum <=> other.to_i
end

#eql?(other) ⇒ true or false

Returns true if self and other are the same type and have equal values.

Returns:

  • (true or false)

137
138
139
# File 'lib/oci8/oracle_version.rb', line 137

def eql?(other)
  other.is_a? OCI8::OracleVersion and (self <=> other) == 0
end

#hashInteger

Returns a hash based on the value of self.

Returns:

  • (Integer)

144
145
146
# File 'lib/oci8/oracle_version.rb', line 144

def hash
  @vernum
end

#to_iInteger

Returns an integer number contains 5-digit Oracle version.

If the hexadecimal notation is 0xAABCCDEE, major, minor, update, patch and port_update are 0xAA, 0xB, 0xCC, 0xD and 0xEE respectively.

Examples:

oraver = OCI8::OracleVersion.new('11.2.0.3')
oraver.to_i          # => 186647296
'%08x' % oraver.to_i # => "0b200300"

Returns:

  • (Integer)

118
119
120
# File 'lib/oci8/oracle_version.rb', line 118

def to_i
  @vernum
end

#to_sString

Returns a dotted version string of the Oracle version.

Examples:

oraver = OCI8::OracleVersion.new('11.2.0.3')
oraver.to_s          # => '11.2.0.3.0'

Returns:


129
130
131
# File 'lib/oci8/oracle_version.rb', line 129

def to_s
  format('%d.%d.%d.%d.%d', @major, @minor, @update, @patch, @port_update)
end