ruby-oci8 2.1.0 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,14 +2,16 @@
2
2
  #
3
3
  # Copyright (C) 2009 KUBO Takehiro <kubo@jiubao.org>
4
4
 
5
- #--
6
-
5
+ #
7
6
  class OCI8
8
7
 
9
- # A data class, representing Oracle version.
8
+ # The data class, representing Oracle version.
10
9
  #
11
10
  # Oracle version is represented by five numbers:
12
11
  # *major*, *minor*, *update*, *patch* and *port_update*.
12
+ #
13
+ # @see OCI8.oracle_client_version
14
+ # @see OCI8#oracle_server_version
13
15
  class OracleVersion
14
16
  include Comparable
15
17
 
@@ -24,7 +26,7 @@ class OCI8
24
26
  # The fourth part of the Oracle version.
25
27
  attr_reader :port_update
26
28
 
27
- # Creates a OCI8::OracleVersion object.
29
+ # Creates an OCI8::OracleVersion object.
28
30
  #
29
31
  # If the first argument _arg_ is a String, it is parsed as dotted
30
32
  # version string. If it is bigger than 0x08000000, it is parsed as
@@ -33,20 +35,32 @@ class OCI8
33
35
  # patch and port_update. Unspecified version numbers are zeros by
34
36
  # default.
35
37
  #
36
- # == Example
37
- # oraver = OCI8::OracleVersion.new('10.2.0.4')
38
- # oraver.major # => 10
38
+ # @example
39
+ # # When the first argument is a String,
40
+ # oraver = OCI8::OracleVersion.new('11.2.0.3')
41
+ # oraver.major # => 11
42
+ # oraver.minor # => 2
43
+ # oraver.update # => 0
44
+ # oraver.patch # => 3
45
+ # oraver.port_update # => 0
46
+ #
47
+ # # When the first argument is bigger than 0x08000000,
48
+ # oraver = OCI8::OracleVersion.new(0x0b200300)
49
+ # oraver.major # => 11
39
50
  # oraver.minor # => 2
40
51
  # oraver.update # => 0
41
- # oraver.patch # => 4
52
+ # oraver.patch # => 3
42
53
  # oraver.port_update # => 0
43
54
  #
44
- # oraver = OCI8::OracleVersion.new(0x0a200400)
45
- # oraver.major # => 10
55
+ # # Otherwise,
56
+ # oraver = OCI8::OracleVersion.new(11, 2, 0, 3)
57
+ # oraver.major # => 11
46
58
  # oraver.minor # => 2
47
59
  # oraver.update # => 0
48
- # oraver.patch # => 4
60
+ # oraver.patch # => 3
49
61
  # oraver.port_update # => 0
62
+ #
63
+ # @return [OCI8::OracleVersion]
50
64
  def initialize(arg, minor = nil, update = nil, patch = nil, port_update = nil)
51
65
  if arg.is_a? String
52
66
  major, minor, update, patch, port_update = arg.split('.').collect do |v|
@@ -68,13 +82,12 @@ class OCI8
68
82
  @port_update = port_update || 0
69
83
  end
70
84
 
71
- # :call-seq:
72
- # oraver <=> other_oraver -> -1, 0, +1
73
- #
74
- # Compares +oraver+ and +other_oraver+.
85
+ # Compares +self+ and +other+.
75
86
  #
76
87
  # <=> is the basis for the methods <, <=, ==, >, >=, and between?,
77
- # included from module Comparable.
88
+ # included from the Comparable module.
89
+ #
90
+ # @return [-1, 0, +1]
78
91
  def <=>(other)
79
92
  cmp = @major <=> other.major
80
93
  return cmp if cmp != 0
@@ -87,57 +100,50 @@ class OCI8
87
100
  @port_update <=> other.port_update
88
101
  end
89
102
 
90
- # :call-seq:
91
- # oraver.to_i -> integer
92
- #
93
103
  # Returns an integer number contains 5-digit Oracle version.
94
104
  #
95
105
  # If the hexadecimal notation is 0xAABCCDEE, *major*, *minor*,
96
106
  # *update*, *patch* and *port_update* are 0xAA, 0xB, 0xCC, 0xD and
97
107
  # 0xEE respectively.
98
108
  #
99
- # == Example
100
- # oraver = OCI8::OracleVersion.new('10.2.0.4')
101
- # oraver.to_i # => 169870336
102
- # '%08x' % oraver.to_i # => "0a200400"
109
+ # @example
110
+ # oraver = OCI8::OracleVersion.new('11.2.0.3')
111
+ # oraver.to_i # => 186647296
112
+ # '%08x' % oraver.to_i # => "0b200300"
113
+ #
114
+ # @return [Integer]
103
115
  def to_i
104
116
  (@major << 24) | (@minor << 20) | (@update << 12) | (@patch << 8) | @port_update
105
117
  end
106
118
 
107
- # :call-seq:
108
- # oraver.to_s -> string
109
- #
110
119
  # Returns a dotted version string of the Oracle version.
111
120
  #
112
- # == Example
113
- # oraver = OCI8::OracleVersion.new('10.2.0.4')
114
- # oraver.to_s # => '10.2.0.4.0'
121
+ # @example
122
+ # oraver = OCI8::OracleVersion.new('11.2.0.3')
123
+ # oraver.to_s # => '11.2.0.3.0'
124
+ #
125
+ # @return [Integer]
115
126
  def to_s
116
127
  format('%d.%d.%d.%d.%d', @major, @minor, @update, @patch, @port_update)
117
128
  end
118
129
 
119
- # :call-seq:
120
- # oraver.eql? other -> true or false
121
- #
122
- # Returns true if +oraver+ and +other+ are the same type and have
130
+ # Returns true if +self+ and +other+ are the same type and have
123
131
  # equal values.
124
- #--
125
- # This is for class Hash to test members for equality.
132
+ #
133
+ # @return [true or false]
126
134
  def eql?(other)
127
135
  other.is_a? OCI8::OracleVersion and (self <=> other) == 0
128
136
  end
129
137
 
130
- # :call-seq:
131
- # oraver.hash -> integer
138
+ # Returns a hash based on the value of +self+.
132
139
  #
133
- # Returns a hash based on the value of +oraver+.
134
- #--
135
- # This is for class Hash.
140
+ # @return [Integer]
136
141
  def hash
137
142
  to_i
138
143
  end
139
144
 
140
- def inspect # :nodoc:
145
+ # @private
146
+ def inspect
141
147
  "#<#{self.class.to_s}: #{self.to_s}>"
142
148
  end
143
149
  end
@@ -2,14 +2,20 @@
2
2
  #
3
3
  # Copyright (C) 2010-2011 KUBO Takehiro <kubo@jiubao.org>
4
4
 
5
+ #
5
6
  class OCI8
6
7
 
7
8
  @@properties = {
8
9
  :length_semantics => :byte,
9
10
  :bind_string_as_nchar => false,
10
11
  :float_conversion_type => :ruby,
12
+ :statement_cache_size => 20,
11
13
  }
12
14
 
15
+ if OCI8.oracle_client_version < OCI8::ORAVER_9_2
16
+ @@properties[:statement_cache_size] = nil
17
+ end
18
+
13
19
  def @@properties.[](name)
14
20
  raise IndexError, "No such property name: #{name}" unless @@properties.has_key?(name)
15
21
  super(name)
@@ -27,6 +33,12 @@ class OCI8
27
33
  when :float_conversion_type
28
34
  # handled by native code in oci8lib_xx.so.
29
35
  OCI8.__set_property(name, val)
36
+ when :statement_cache_size
37
+ if OCI8.oracle_client_version < OCI8::ORAVER_9_2
38
+ raise RuntimeError, ":statement_cache_size is disabled on Oracle 9iR1 client."
39
+ end
40
+ val = val.to_i
41
+ raise ArgumentError, "The property value for :statement_cache_size must not be negative." if val < 0
30
42
  end
31
43
  super(name, val)
32
44
  end
@@ -74,6 +86,13 @@ class OCI8
74
86
  # 15.700000000000001 by Float#to_s.
75
87
  # See: http://rubyforge.org/forum/forum.php?thread_id=50030&forum_id=1078
76
88
  #
89
+ # [:statement_cache_size]
90
+ # (new in 2.1.1)
91
+ #
92
+ # The statement cache size per each session. The default value is 20 statements.
93
+ # This feature is available on Oracle 9iR2 or later.
94
+ # See: http://docs.oracle.com/cd/E11882_01/appdev.112/e10646/oci09adv.htm#i471377
95
+ #
77
96
  def self.properties
78
97
  @@properties
79
98
  end
data/pre-distclean.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  rm_f "#{curr_objdir}/lib/oci8.rb"
2
+ rm_f "#{curr_objdir}/ext/oci8/oci8lib_18.map"
3
+ rm_f "#{curr_objdir}/ext/oci8/oci8lib_191.map"
2
4
  if RUBY_PLATFORM =~ /cygwin/
3
5
  rm_f "#{curr_objdir}/ext/oci8/OCI.def"
4
6
  rm_f "#{curr_objdir}/ext/oci8/libOCI.a"
5
- else
6
- rm_f "#{curr_objdir}/ext/oci8/oracle_objs.a"
7
7
  end
data/ruby-oci8.gemspec CHANGED
@@ -31,7 +31,7 @@ spec = Gem::Specification.new do |s|
31
31
  s.description = <<EOS
32
32
  ruby-oci8 is a ruby interface for Oracle using OCI8 API. It is available with Oracle8, Oracle8i, Oracle9i, Oracle10g and Oracle Instant Client.
33
33
  EOS
34
- s.has_rdoc = true
34
+ s.has_rdoc = 'yard'
35
35
  s.authors = ['KUBO Takehiro']
36
36
  s.platform = gem_platform
37
37
  files = File.read('dist-files').split("\n")
@@ -54,6 +54,10 @@ EOS
54
54
  else
55
55
  raise "No compiled binary are found. Run make in advance."
56
56
  end
57
+ # add map files to analyze a core (minidump) file.
58
+ so_files << 'ext/oci8/oci8lib_18.map' if has_1_8 and File.exists? 'ext/oci8/oci8lib_18.map'
59
+ so_files << 'ext/oci8/oci8lib_191.map' if has_1_9_1 and File.exists? 'ext/oci8/oci8lib_191.map'
60
+
57
61
  FileUtils.copy so_files, 'lib', :preserve => true
58
62
  files.reject! do |fname|
59
63
  fname =~ /^ext/
@@ -63,8 +67,8 @@ EOS
63
67
  end
64
68
  files << 'lib/oci8.rb'
65
69
  end
70
+ s.require_paths = ['lib', 'ext/oci8']
66
71
  s.files = files
67
72
  s.test_files = 'test/test_all.rb'
68
- s.rdoc_options = ['--main', 'README']
69
- s.extra_rdoc_files = ['README']
73
+ s.extra_rdoc_files = ['README.md']
70
74
  end
data/test/config.rb CHANGED
@@ -13,12 +13,7 @@ ENV['ORA_NCHAR_LITERAL_REPLACE'] = 'TRUE' if OCI8.client_charset_name.include? '
13
13
  nls_lang = ENV['NLS_LANG']
14
14
  nls_lang = nls_lang.split('.')[1] unless nls_lang.nil?
15
15
  nls_lang = nls_lang.upcase unless nls_lang.nil?
16
- case nls_lang
17
- when 'JA16EUC'
18
- $lobfile = File.dirname(__FILE__) + '/../doc/api.ja.rd' # EUC-JP file
19
- else
20
- $lobfile = File.dirname(__FILE__) + '/../doc/api.en.rd' # ASCII file
21
- end
16
+ $lobfile = File.dirname(__FILE__) + '/../setup.rb'
22
17
  $lobreadnum = 256 # counts in charactors
23
18
 
24
19
  # don't modify below.
@@ -13,15 +13,22 @@ class TestDateTime < Test::Unit::TestCase
13
13
  end
14
14
  end
15
15
 
16
+ @@time_new_accepts_timezone = begin
17
+ Time.new(2001, 1, 1, 0, 0, 0, '+00:00')
18
+ true
19
+ rescue
20
+ false
21
+ end
22
+
16
23
  def string_to_time(str)
17
- /(\d+)-(\d+)-(\d+) ?(?:(\d+):(\d+):(\d+))?(?:\.(\d+))? ?([+-]\d+:\d+)?/ =~ str
24
+ /(\d+)-(\d+)-(\d+) ?(?:(\d+):(\d+):(\d+))?(?:\.(\d+))? ?(([+-])(\d+):(\d+))?/ =~ str
18
25
  args = []
19
26
  args << $1.to_i # year
20
27
  args << $2.to_i # month
21
28
  args << $3.to_i # day
22
29
  args << $4.to_i if $4 # hour
23
30
  args << $5.to_i if $5 # minute
24
- if $8
31
+ if $8 and @@time_new_accepts_timezone
25
32
  args << $6.to_i + $7.to_i.to_r / ('1' + '0' * ($7.length)).to_i
26
33
  args << $8
27
34
  Time.new(*args)
@@ -32,15 +39,37 @@ class TestDateTime < Test::Unit::TestCase
32
39
  if $7
33
40
  args << $7.to_i.to_r * 1000000 / ('1' + '0' * ($7.length)).to_i
34
41
  end
35
- # no time zone
36
- Time.local(*args)
42
+ if $8
43
+ # with time zone
44
+ offset = ($9 + '1').to_i * ($10.to_i * 60 + $11.to_i)
45
+ if offset == 0
46
+ Time.utc(*args)
47
+ else
48
+ tm = Time.local(*args)
49
+ raise "Failed to convert #{str} to Time" if tm.utc_offset != offset * 60
50
+ tm
51
+ end
52
+ else
53
+ # without time zone
54
+ Time.local(*args)
55
+ end
37
56
  end
38
57
  #Time.local(*str.split(/[- :\.]/).collect do |n| n.to_i; end)
39
58
  end
40
59
 
60
+ def string_to_datetime(str)
61
+ /(\d+-\d+-\d+ ?(?:\d+:\d+:\d+)?(?:\.\d+)?) ?([+-]\d+:\d+)?/ =~ str
62
+ if $2
63
+ # with time zone
64
+ DateTime.parse(str)
65
+ else
66
+ tm = string_to_time(str)
67
+ DateTime.parse(str + timezone_string(*((tm.utc_offset / 60).divmod 60)))
68
+ end
69
+ end
70
+
41
71
  def setup
42
72
  @conn = get_oci8_connection
43
- @local_timezone = timezone_string(*((::Time.now.utc_offset / 60).divmod 60))
44
73
  end
45
74
 
46
75
  def teardown
@@ -48,7 +77,8 @@ class TestDateTime < Test::Unit::TestCase
48
77
  end
49
78
 
50
79
  def test_date_select
51
- ['2005-12-31 23:59:59',
80
+ ['2005-06-01 00:00:00',
81
+ '2005-12-31 23:59:59',
52
82
  '2006-01-01 00:00:00'].each do |date|
53
83
  @conn.exec(<<-EOS) do |row|
54
84
  SELECT TO_DATE('#{date}', 'YYYY-MM-DD HH24:MI:SS') FROM dual
@@ -66,11 +96,12 @@ END;
66
96
  EOS
67
97
  cursor.bind_param(:out, nil, DateTime)
68
98
  cursor.bind_param(:in, nil, String, 36)
69
- ['2005-12-31 23:59:59',
99
+ ['2005-06-01 00:00:00',
100
+ '2005-12-31 23:59:59',
70
101
  '2006-01-01 00:00:00'].each do |date|
71
102
  cursor[:in] = date
72
103
  cursor.exec
73
- assert_equal(DateTime.parse(date + @local_timezone), cursor[:out])
104
+ assert_equal(string_to_datetime(date), cursor[:out])
74
105
  end
75
106
  cursor.close
76
107
  end
@@ -86,9 +117,10 @@ END;
86
117
  EOS
87
118
  cursor.bind_param(:out, nil, String, 33)
88
119
  cursor.bind_param(:in, nil, DateTime)
89
- ['2005-12-31 23:59:59',
120
+ ['2005-06-01 00:00:00',
121
+ '2005-12-31 23:59:59',
90
122
  '2006-01-01 00:00:00'].each do |date|
91
- cursor[:in] = DateTime.parse(date + @local_timezone)
123
+ cursor[:in] = string_to_datetime(date)
92
124
  cursor.exec
93
125
  assert_equal(date, cursor[:out])
94
126
  end
@@ -96,7 +128,8 @@ EOS
96
128
  end
97
129
 
98
130
  def test_timestamp_select
99
- ['2005-12-31 23:59:59.999999000',
131
+ ['2005-06-01 00:00:00.999999000',
132
+ '2005-12-31 23:59:59.999999000',
100
133
  '2006-01-01 00:00:00.000000000'].each do |date|
101
134
  @conn.exec(<<-EOS) do |row|
102
135
  SELECT TO_TIMESTAMP('#{date}', 'YYYY-MM-DD HH24:MI:SS.FF') FROM dual
@@ -114,11 +147,12 @@ END;
114
147
  EOS
115
148
  cursor.bind_param(:out, nil, DateTime)
116
149
  cursor.bind_param(:in, nil, String, 36)
117
- ['2005-12-31 23:59:59.999999000',
150
+ ['2005-06-01 00:00:00.999999000',
151
+ '2005-12-31 23:59:59.999999000',
118
152
  '2006-01-01 00:00:00.000000000'].each do |date|
119
153
  cursor[:in] = date
120
154
  cursor.exec
121
- assert_equal(DateTime.parse(date + @local_timezone), cursor[:out])
155
+ assert_equal(string_to_datetime(date), cursor[:out])
122
156
  end
123
157
  cursor.close
124
158
  end
@@ -131,9 +165,10 @@ END;
131
165
  EOS
132
166
  cursor.bind_param(:out, nil, String, 33)
133
167
  cursor.bind_param(:in, nil, DateTime)
134
- ['2005-12-31 23:59:59.999999000',
168
+ ['2005-06-01 00:00:00.999999000',
169
+ '2005-12-31 23:59:59.999999000',
135
170
  '2006-01-01 00:00:00.000000000'].each do |date|
136
- cursor[:in] = DateTime.parse(date + @local_timezone)
171
+ cursor[:in] = string_to_datetime(date)
137
172
  cursor.exec
138
173
  assert_equal(date, cursor[:out])
139
174
  end
@@ -141,7 +176,8 @@ EOS
141
176
  end
142
177
 
143
178
  def test_timestamp_tz_select
144
- ['2005-12-31 23:59:59.999999000 +08:30',
179
+ ['2005-06-01 00:00:00.999999000 +00:00',
180
+ '2005-12-31 23:59:59.999999000 +08:30',
145
181
  '2006-01-01 00:00:00.000000000 -08:30'].each do |date|
146
182
  @conn.exec(<<-EOS) do |row|
147
183
  SELECT TO_TIMESTAMP_TZ('#{date}', 'YYYY-MM-DD HH24:MI:SS.FF TZH:TZM') FROM dual
@@ -149,7 +185,7 @@ EOS
149
185
  expected_val = begin
150
186
  string_to_time(date)
151
187
  rescue
152
- DateTime.parse(date)
188
+ string_to_datetime(date)
153
189
  end
154
190
  assert_equal(expected_val, row[0])
155
191
  end
@@ -164,11 +200,12 @@ END;
164
200
  EOS
165
201
  cursor.bind_param(:out, nil, DateTime)
166
202
  cursor.bind_param(:in, nil, String, 36)
167
- ['2005-12-31 23:59:59.999999000 +08:30',
168
- '2006-01-01 00:00:00.000000000 -08:30'].each do |date|
203
+ ['2005-06-01 00:00:00.999999000 -08:30',
204
+ '2005-12-31 23:59:59.999999000 +00:00',
205
+ '2006-01-01 00:00:00.000000000 +08:30'].each do |date|
169
206
  cursor[:in] = date
170
207
  cursor.exec
171
- assert_equal(DateTime.parse(date), cursor[:out])
208
+ assert_equal(string_to_datetime(date), cursor[:out])
172
209
  end
173
210
  cursor.close
174
211
  end
@@ -181,9 +218,10 @@ END;
181
218
  EOS
182
219
  cursor.bind_param(:out, nil, String, 36)
183
220
  cursor.bind_param(:in, nil, DateTime)
184
- ['2005-12-31 23:59:59.999999000 +08:30',
185
- '2006-01-01 00:00:00.000000000 -08:30'].each do |date|
186
- cursor[:in] = DateTime.parse(date)
221
+ ['2005-06-01 00:00:00.999999999 +08:30',
222
+ '2005-12-31 23:59:59.999999000 -08:30',
223
+ '2006-01-01 00:00:00.000000000 +00:00'].each do |date|
224
+ cursor[:in] = string_to_datetime(date)
187
225
  cursor.exec
188
226
  assert_equal(date, cursor[:out])
189
227
  end
@@ -201,48 +239,48 @@ EOS
201
239
  def obj.day; 31; end
202
240
  cursor[:in] = obj
203
241
  cursor.exec
204
- assert_equal(DateTime.parse('2006-12-31 00:00:00' + @local_timezone), cursor[:out])
242
+ assert_equal(string_to_datetime('2006-12-31 00:00:00'), cursor[:out])
205
243
  # test hour
206
244
  def obj.hour; 23; end
207
245
  cursor[:in] = obj
208
246
  cursor.exec
209
- assert_equal(DateTime.parse('2006-12-31 23:00:00' + @local_timezone), cursor[:out])
247
+ assert_equal(string_to_datetime('2006-12-31 23:00:00'), cursor[:out])
210
248
  # test min
211
249
  def obj.min; 59; end
212
250
  cursor[:in] = obj
213
251
  cursor.exec
214
- assert_equal(DateTime.parse('2006-12-31 23:59:00' + @local_timezone), cursor[:out])
252
+ assert_equal(string_to_datetime('2006-12-31 23:59:00'), cursor[:out])
215
253
  # test sec
216
254
  def obj.sec; 59; end
217
255
  cursor[:in] = obj
218
256
  cursor.exec
219
- assert_equal(DateTime.parse('2006-12-31 23:59:59' + @local_timezone), cursor[:out])
257
+ assert_equal(string_to_datetime('2006-12-31 23:59:59'), cursor[:out])
220
258
 
221
259
  # test sec_fraction
222
260
  def obj.sec_fraction; DateTime.parse('0001-01-01 00:00:00.000001').sec_fraction * 999999 ; end
223
261
  cursor[:in] = obj
224
262
  cursor.exec
225
- assert_equal(DateTime.parse('2006-12-31 23:59:59.999999' + @local_timezone), cursor[:out])
263
+ assert_equal(string_to_datetime('2006-12-31 23:59:59.999999'), cursor[:out])
226
264
  # test utc_offset (Time)
227
265
  def obj.utc_offset; @utc_offset; end
228
266
  obj.instance_variable_set(:@utc_offset, 9 * 60 * 60)
229
267
  cursor[:in] = obj
230
268
  cursor.exec
231
- assert_equal(DateTime.parse('2006-12-31 23:59:59.999999 +09:00'), cursor[:out])
269
+ assert_equal(string_to_datetime('2006-12-31 23:59:59.999999 +09:00'), cursor[:out])
232
270
  obj.instance_variable_set(:@utc_offset, -5 * 60 * 60)
233
271
  cursor[:in] = obj
234
272
  cursor.exec
235
- assert_equal(DateTime.parse('2006-12-31 23:59:59.999999 -05:00'), cursor[:out])
273
+ assert_equal(string_to_datetime('2006-12-31 23:59:59.999999 -05:00'), cursor[:out])
236
274
  # test offset (DateTime)
237
275
  def obj.offset; @offset; end
238
276
  obj.instance_variable_set(:@offset, 9.to_r / 24)
239
277
  cursor[:in] = obj
240
278
  cursor.exec
241
- assert_equal(DateTime.parse('2006-12-31 23:59:59.999999 +09:00'), cursor[:out])
279
+ assert_equal(string_to_datetime('2006-12-31 23:59:59.999999 +09:00'), cursor[:out])
242
280
  obj.instance_variable_set(:@offset, -5.to_r / 24)
243
281
  cursor[:in] = obj
244
282
  cursor.exec
245
- assert_equal(DateTime.parse('2006-12-31 23:59:59.999999 -05:00'), cursor[:out])
283
+ assert_equal(string_to_datetime('2006-12-31 23:59:59.999999 -05:00'), cursor[:out])
246
284
  end
247
285
 
248
286
  def test_timezone