Class: OCI8::OracleVersion
- Inherits:
-
Object
- Object
- OCI8::OracleVersion
- 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
-
#major ⇒ Object
readonly
The first part of the Oracle version.
-
#minor ⇒ Object
readonly
The second part of the Oracle version.
-
#patch ⇒ Object
readonly
The fourth part of the Oracle version.
-
#port_update ⇒ Object
readonly
The fifth part of the Oracle version.
-
#update ⇒ Object
readonly
The third part of the Oracle version.
Instance Method Summary collapse
-
#<=>(other) ⇒ -1, ...
Compares
self
andother
. -
#eql?(other) ⇒ true or false
Returns true if
self
andother
are the same type and have equal values. -
#hash ⇒ Integer
Returns a hash based on the value of
self
. -
#initialize(arg, minor = nil, update = nil, patch = nil, port_update = nil) ⇒ OCI8::OracleVersion
constructor
Creates an OCI8::OracleVersion object.
-
#to_i ⇒ Integer
Returns an integer number contains 5-digit Oracle version.
-
#to_s ⇒ String
Returns a dotted version string of the Oracle version.
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.
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
#major ⇒ Object (readonly)
The first part of the Oracle version.
19 20 21 |
# File 'lib/oci8/oracle_version.rb', line 19 def major @major end |
#minor ⇒ Object (readonly)
The second part of the Oracle version.
21 22 23 |
# File 'lib/oci8/oracle_version.rb', line 21 def minor @minor end |
#patch ⇒ Object (readonly)
The fourth part of the Oracle version.
25 26 27 |
# File 'lib/oci8/oracle_version.rb', line 25 def patch @patch end |
#port_update ⇒ Object (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 |
#update ⇒ Object (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.
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.
145 146 147 |
# File 'lib/oci8/oracle_version.rb', line 145 def eql?(other) other.is_a? OCI8::OracleVersion and (self <=> other) == 0 end |
#hash ⇒ Integer
Returns a hash based on the value of self
.
152 153 154 |
# File 'lib/oci8/oracle_version.rb', line 152 def hash @vernum end |
#to_i ⇒ Integer
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.
118 119 120 |
# File 'lib/oci8/oracle_version.rb', line 118 def to_i @vernum end |
#to_s ⇒ String
Returns a dotted version string of the Oracle version.
129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/oci8/oracle_version.rb', line 129 def to_s version_format = if @major >= 23 && @patch != 0 && @port_update != 0 # The fifth numeral is the release month (01 through 12) since Oracle 23ai # See https://docs.oracle.com/en/database/oracle/oracle-database/23/upgrd/oracle-database-release-numbers.html#GUID-1E2F3945-C0EE-4EB2-A933-8D1862D8ECE2__GUID-704EC7BB-4EEA-4A92-96FC-579B216DCA97 '%d.%d.%d.%d.%02d' else '%d.%d.%d.%d.%d' end format(version_format, @major, @minor, @update, @patch, @port_update) end |