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.

See Also:

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
# 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 >= 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
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 fifth part of the Oracle version.



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

def patch
  @patch
end

#port_updateObject (readonly)

The fourth 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)


91
92
93
94
95
96
97
98
99
100
101
# File 'lib/oci8/oracle_version.rb', line 91

def <=>(other)
  cmp = @major <=> other.major
  return cmp if cmp != 0
  cmp = @minor <=> other.minor
  return cmp if cmp != 0
  cmp = @update <=> other.update
  return cmp if cmp != 0
  cmp = @patch <=> other.patch
  return cmp if cmp != 0
  @port_update <=> other.port_update
end

#eql?(other) ⇒ true or false

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

Returns:

  • (true or false)


134
135
136
# File 'lib/oci8/oracle_version.rb', line 134

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)


141
142
143
# File 'lib/oci8/oracle_version.rb', line 141

def hash
  to_i
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)


115
116
117
# File 'lib/oci8/oracle_version.rb', line 115

def to_i
  (@major << 24) | (@minor << 20) | (@update << 12) | (@patch << 8) | @port_update
end

#to_sInteger

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:

  • (Integer)


126
127
128
# File 'lib/oci8/oracle_version.rb', line 126

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